Skip to content

Commit

Permalink
deprecate and update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Mar 7, 2019
1 parent 7d69b0d commit 203b76b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/api/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ event. The [DownloadItem](download-item.md) will not have any `WebContents` asso
the initial state will be `interrupted`. The download will start only when the
`resume` API is called on the [DownloadItem](download-item.md).

#### `ses.clearAuthCache(options, callback)`

* `options` ([RemovePassword](structures/remove-password.md) | [RemoveClientCertificate](structures/remove-client-certificate.md))
* `callback` Function - Called when operation is done.

Clears the session’s HTTP authentication cache.

**[Deprecated Soon](promisification.md)**

#### `ses.clearAuthCache(options)`

* `options` ([RemovePassword](structures/remove-password.md) | [RemoveClientCertificate](structures/remove-client-certificate.md))
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/api/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Session.prototype._init = function () {
app.emit('session-created', this)
}

Session.prototype.clearAuthCache = deprecate.promisify(Session.prototype.clearAuthCache)

Cookies.prototype.flushStore = deprecate.promisify(Cookies.prototype.flushStore)
Cookies.prototype.get = deprecate.promisify(Cookies.prototype.get)
Cookies.prototype.remove = deprecate.promisify(Cookies.prototype.remove)
Expand Down
55 changes: 54 additions & 1 deletion spec/api-session-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ describe('session module', () => {
})
})

describe('ses.clearAuthCache(options[, callback])', () => {
describe('ses.clearAuthCache(options)', () => {
it('can clear http auth info from cache', (done) => {
const ses = session.fromPartition('auth-cache')
const server = http.createServer((req, res) => {
Expand Down Expand Up @@ -938,6 +938,59 @@ describe('session module', () => {
issueLoginRequest()
})
})

// TODO(codebytere): remove when promisification complete
it('can clear http auth info from cache (callback)', (done) => {
const ses = session.fromPartition('auth-cache')
const server = http.createServer((req, res) => {
const credentials = auth(req)
if (!credentials || credentials.name !== 'test' || credentials.pass !== 'test') {
res.statusCode = 401
res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"')
res.end()
} else {
res.end('authenticated')
}
})
server.listen(0, '127.0.0.1', () => {
const port = server.address().port
function issueLoginRequest (attempt = 1) {
if (attempt > 2) {
server.close()
return done()
}
const request = net.request({
url: `http://127.0.0.1:${port}`,
session: ses
})
request.on('login', (info, callback) => {
attempt += 1
assert.strictEqual(info.scheme, 'basic')
assert.strictEqual(info.realm, 'Restricted')
callback('test', 'test')
})
request.on('response', (response) => {
let data = ''
response.pause()
response.on('data', (chunk) => {
data += chunk
})
response.on('end', () => {
assert.strictEqual(data, 'authenticated')
ses.clearAuthCache({ type: 'password' }, () => {
issueLoginRequest(attempt)
})
})
response.on('error', (error) => { done(error) })
response.resume()
})
// Internal api to bypass cache for testing.
request.urlRequest._setLoadFlags(1 << 1)
request.end()
}
issueLoginRequest()
})
})
})

describe('ses.setPermissionRequestHandler(handler)', () => {
Expand Down

0 comments on commit 203b76b

Please sign in to comment.