-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📦 NEW: Support digest auth (#390)
closes #388
- Loading branch information
Showing
6 changed files
with
205 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
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
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,77 @@ | ||
import { strict as assert } from 'assert'; | ||
import urllib from '../src'; | ||
import { startServer } from './fixtures/server'; | ||
|
||
describe('options.digestAuth.test.ts', () => { | ||
let close: any; | ||
let _url: string; | ||
beforeAll(async () => { | ||
const { closeServer, url } = await startServer(); | ||
close = closeServer; | ||
_url = url; | ||
}); | ||
|
||
afterAll(async () => { | ||
await close(); | ||
}); | ||
|
||
it('should auth pass', async () => { | ||
const response = await urllib.request(`${_url}digestAuth`, { | ||
digestAuth: 'user:pwd', | ||
dataType: 'json', | ||
}); | ||
assert.equal(response.status, 200); | ||
assert(response.data.authorization); | ||
// console.log(response.data); | ||
assert.match(response.data.authorization, /Digest username="user", realm="testrealm@urllib.com", nonce="/); | ||
}); | ||
|
||
it('should auth fail', async () => { | ||
const response = await urllib.request(`${_url}digestAuth`, { | ||
digestAuth: 'invailduser:pwd', | ||
dataType: 'json', | ||
}); | ||
assert.equal(response.status, 401); | ||
assert.deepEqual(response.data, { | ||
error: 'authorization invaild', | ||
}); | ||
}); | ||
|
||
it('should digest auth required', async () => { | ||
const response = await urllib.request(`${_url}digestAuth?t=123123`, { | ||
dataType: 'json', | ||
}); | ||
assert.equal(response.status, 401); | ||
assert.deepEqual(response.data, { | ||
error: 'authorization required', | ||
}); | ||
}); | ||
|
||
it.skip('should request with digest auth success in httpbin', async () => { | ||
var url = 'https://httpbin.org/digest-auth/auth/user/passwd'; | ||
const response = await urllib.request(url, { | ||
digestAuth: 'user:passwd', | ||
dataType: 'json', | ||
timeout: 10000, | ||
}); | ||
console.log(response.headers); | ||
assert.equal(response.status, 200); | ||
assert.deepEqual(response.data, { | ||
user: 'user', | ||
authenticated: true, | ||
}); | ||
}); | ||
|
||
it.skip('should request with digest auth fail in httpbin', async () => { | ||
var url = 'https://httpbin.org/digest-auth/auth/user/passwd'; | ||
const response = await urllib.request(url, { | ||
digestAuth: 'user:passwdfail', | ||
dataType: 'json', | ||
timeout: 10000, | ||
}); | ||
// console.log(response.headers); | ||
assert(response.headers['www-authenticate']); | ||
assert.equal(response.status, 401); | ||
assert.equal(response.data, null); | ||
}); | ||
}); |