fix: implement 'login' event for net.ClientRequest (#21096)
This commit is contained in:
parent
878ab916d2
commit
4f1536479e
16 changed files with 445 additions and 38 deletions
|
@ -1534,7 +1534,7 @@ describe('webContents module', () => {
|
|||
}
|
||||
response
|
||||
.writeHead(401, { 'WWW-Authenticate': 'Basic realm="Foo"' })
|
||||
.end()
|
||||
.end('401')
|
||||
}).listen(0, '127.0.0.1', () => {
|
||||
serverPort = (server.address() as AddressInfo).port
|
||||
serverUrl = `http://127.0.0.1:${serverPort}`
|
||||
|
@ -1557,6 +1557,10 @@ describe('webContents module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await session.defaultSession.clearAuthCache({ type: 'password' })
|
||||
})
|
||||
|
||||
after(() => {
|
||||
server.close()
|
||||
proxyServer.close()
|
||||
|
@ -1607,5 +1611,16 @@ describe('webContents module', () => {
|
|||
expect(eventAuthInfo.port).to.equal(proxyServerPort)
|
||||
expect(eventAuthInfo.realm).to.equal('Foo')
|
||||
})
|
||||
|
||||
it('cancels authentication when callback is called with no arguments', async () => {
|
||||
const w = new BrowserWindow({ show: false })
|
||||
w.webContents.on('login', (event, request, authInfo, cb) => {
|
||||
event.preventDefault()
|
||||
cb()
|
||||
})
|
||||
await w.loadURL(serverUrl)
|
||||
const body = await w.webContents.executeJavaScript(`document.documentElement.textContent`)
|
||||
expect(body).to.equal('401')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue