|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import {strict as assert} from 'assert'; |
| 4 | +import settings from '../../../node/utils/Settings'; |
| 5 | +import {anonymizeIp} from '../../../node/utils/anonymizeIp'; |
| 6 | + |
| 7 | +describe(__filename, function () { |
| 8 | + const backup = {ipLogging: settings.ipLogging, disableIPlogging: settings.disableIPlogging}; |
| 9 | + |
| 10 | + afterEach(function () { |
| 11 | + settings.ipLogging = backup.ipLogging; |
| 12 | + settings.disableIPlogging = backup.disableIPlogging; |
| 13 | + }); |
| 14 | + |
| 15 | + describe('settings.ipLogging is honoured by anonymizeIp', function () { |
| 16 | + it('anonymous mode redacts a concrete IPv4', function () { |
| 17 | + settings.ipLogging = 'anonymous'; |
| 18 | + assert.equal(anonymizeIp('8.8.8.8', settings.ipLogging), 'ANONYMOUS'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('full mode passes the IP through unchanged', function () { |
| 22 | + settings.ipLogging = 'full'; |
| 23 | + assert.equal(anonymizeIp('8.8.8.8', settings.ipLogging), '8.8.8.8'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('truncated mode zeros the last v4 octet', function () { |
| 27 | + settings.ipLogging = 'truncated'; |
| 28 | + assert.equal(anonymizeIp('8.8.8.8', settings.ipLogging), '8.8.8.0'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('truncated mode keeps the first /48 of a v6 address', function () { |
| 32 | + settings.ipLogging = 'truncated'; |
| 33 | + assert.equal(anonymizeIp('2001:db8::1', settings.ipLogging), '2001:db8::'); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('disableIPlogging → ipLogging deprecation shim', function () { |
| 38 | + // Replicates the shim block from Settings.ts::reloadSettings so we can |
| 39 | + // assert the mapping without rebooting the whole server in this spec. |
| 40 | + const applyShim = (parsed: Record<string, any>) => { |
| 41 | + if (parsed != null && 'disableIPlogging' in parsed && !('ipLogging' in parsed)) { |
| 42 | + settings.ipLogging = parsed.disableIPlogging ? 'anonymous' : 'full'; |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + it('maps disableIPlogging=true to ipLogging=anonymous', function () { |
| 47 | + settings.ipLogging = 'full'; |
| 48 | + applyShim({disableIPlogging: true}); |
| 49 | + assert.equal(settings.ipLogging, 'anonymous'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('maps disableIPlogging=false to ipLogging=full', function () { |
| 53 | + settings.ipLogging = 'anonymous'; |
| 54 | + applyShim({disableIPlogging: false}); |
| 55 | + assert.equal(settings.ipLogging, 'full'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('leaves ipLogging alone when the operator set both', function () { |
| 59 | + settings.ipLogging = 'truncated'; |
| 60 | + applyShim({disableIPlogging: true, ipLogging: 'truncated'}); |
| 61 | + assert.equal(settings.ipLogging, 'truncated'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('does nothing when neither key is present', function () { |
| 65 | + settings.ipLogging = 'anonymous'; |
| 66 | + applyShim({}); |
| 67 | + assert.equal(settings.ipLogging, 'anonymous'); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments