obscure authorization header value when logging
[squeep-api-dingus] / test / lib / common.js
index b802003af74c0a50d5a9ecf538c364df8eb682b7..bacd6be3d54d2aaa7e6b019c98e0e664050392dc 100644 (file)
@@ -141,6 +141,46 @@ describe('common', function () {
     });
   }); // requestLogData
 
+  describe('obscureAuthorizationHeader', function () {
+    it('obscures basic data', function () {
+      const authHeader = 'Basic Zm9vOmJhcg==';
+      const expected = 'Basic ************';
+      const result = common.obscureAuthorizationHeader(authHeader);
+      assert.strictEqual(result, expected);
+    });
+    it('obscures all of other types', function () {
+      const authHeader = 'someWeirdAuth';
+      const expected = '*************';
+      const result = common.obscureAuthorizationHeader(authHeader);
+      assert.strictEqual(result, expected);
+    });
+    it('does nothing when empty', function () {
+      const authHeader = undefined;
+      const expected = undefined;
+      const result = common.obscureAuthorizationHeader(authHeader);
+      assert.strictEqual(result, expected);
+    });
+  }); // obscureAuthorizationHeader
+
+  describe('scrubHeaderObject', function () {
+    it('', function () {
+      const data = {
+        headers: {
+          'foo': 'bar',
+          'authorization': 'Basic Zm9vOmJhcg==',
+        },
+      };
+      const expected = {
+        headers: {
+          'foo': 'bar',
+          'authorization': 'Basic ************',
+        },
+      };
+      common.scrubHeaderObject(data);
+      assert.deepStrictEqual(data, expected);
+    });
+  }); // scrubHeaderObject
+
   describe('responseLogData', function () {
     it('gives data', function () {
       const res = {
@@ -258,7 +298,6 @@ describe('common', function () {
     });
   }); // requestId
 
-
   describe('ensureLoggerLevels', function () {
     it('adds missing levels', function () {
       const result = common.ensureLoggerLevels();
@@ -378,4 +417,26 @@ describe('common', function () {
     });
   }); // mergeDeep
 
+  describe('unfoldHeaderLines', function () {
+    it('folds', function () {
+      const lines = [
+        'Normal-Header: some header data',
+        'Folded-Header: more data',
+        '   second line of data',
+        '   third line of data',
+      ];
+      const expected = [
+        'Normal-Header: some header data',
+        'Folded-Header: more data second line of data third line of data',
+      ];
+      const result = common.unfoldHeaderLines(lines);
+      assert.deepStrictEqual(result, expected);
+    });
+    it('covers no input', function () {
+      const lines = undefined;
+      const result = common.unfoldHeaderLines();
+      assert.deepStrictEqual(result, lines);
+    });
+  }); // unfoldHeaderLines
+
 });