-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide password values from raw HTTP logs. (#4066)
Co-authored-by: Priyansh Garg <[email protected]>
- Loading branch information
1 parent
3502e34
commit a441ca4
Showing
5 changed files
with
125 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/sampletests/passwordValueRedacted/passwordValueRedacted.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('value redaction in setPassword', function() { | ||
test('test setPassword', async browser => { | ||
browser | ||
.setPassword('#weblogin', 'password') | ||
.setValue('#weblogin', 'simpletext'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const {Key} = require('selenium-webdriver'); | ||
const common = require('../../../../common.js'); | ||
const Mocks = require('../../../../lib/command-mocks.js'); | ||
const {settings} = common; | ||
const NightwatchClient = common.require('index.js'); | ||
const MockServer = require('../../../../lib/mockserver.js'); | ||
|
||
describe('setPassword report check', function() { | ||
before(function(done) { | ||
this.server = MockServer.init(); | ||
this.server.on('listening', () => done()); | ||
}); | ||
|
||
after(function(done) { | ||
this.server.close(function() { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('client.setPassword() value redacted in rawHttpOutput', async function() { | ||
let sendKeysPasswordMockCalled = false; | ||
let sendKeysNormalMockCalled = false; | ||
let globalReporterCalled = false; | ||
|
||
Mocks.createNewW3CSession({ | ||
testName: 'Actions API demo tests' | ||
}); | ||
|
||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/5cc459b8-36a8-3042-8b4a-258883ea642b/clear', | ||
method: 'POST', | ||
statusCode: 200, | ||
response: { | ||
value: null | ||
}, | ||
times: 2 | ||
}); | ||
|
||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/5cc459b8-36a8-3042-8b4a-258883ea642b/value', | ||
method: 'POST', | ||
postdata: {text: Key.NULL + 'password', value: [Key.NULL, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd']}, | ||
response: { | ||
value: null | ||
}, | ||
onRequest: () => { | ||
sendKeysPasswordMockCalled = true; | ||
} | ||
}, true); | ||
|
||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/5cc459b8-36a8-3042-8b4a-258883ea642b/value', | ||
method: 'POST', | ||
postdata: {text: 'simpletext', value: ['s', 'i', 'm', 'p', 'l', 'e', 't', 'e', 'x', 't']}, | ||
response: { | ||
value: null | ||
}, | ||
onRequest: () => { | ||
sendKeysNormalMockCalled = true; | ||
} | ||
}, true); | ||
|
||
const testsPath = [ | ||
path.join(__dirname, '../../../../sampletests/passwordValueRedacted/passwordValueRedacted.js') | ||
]; | ||
|
||
const globals = { | ||
reporter(results) { | ||
globalReporterCalled = true; | ||
|
||
assert.strictEqual(sendKeysPasswordMockCalled, true); | ||
assert.strictEqual(sendKeysNormalMockCalled, true); | ||
assert.strictEqual(results.errmessages.length, 0); | ||
|
||
const rawHttpOutput = results.modules.passwordValueRedacted.rawHttpOutput; | ||
const requests = rawHttpOutput | ||
.filter((req) => { | ||
return req[1].includes('element/5cc459b8-36a8-3042-8b4a-258883ea642b/value') && | ||
req[1].includes('Request POST'); | ||
}); | ||
|
||
assert.strictEqual(requests.length, 2); | ||
|
||
// First request (setPassword) should contain redacted value | ||
assert.strictEqual(requests[0][2].includes('password'), false); | ||
assert.strictEqual(requests[0][2].includes('*******'), true); | ||
|
||
// Second request (setValue) should NOT contain redacted value | ||
assert.strictEqual(requests[1][2].includes('simpletext'), true); | ||
assert.strictEqual(requests[1][2].includes('*******'), false); | ||
} | ||
}; | ||
|
||
await NightwatchClient.runTests(testsPath, settings({ | ||
globals, | ||
output_folder: 'output', | ||
selenium_host: null | ||
})); | ||
|
||
assert.strictEqual(globalReporterCalled, true); | ||
}); | ||
}); |