This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c715044
commit 7af5adf
Showing
12 changed files
with
1,615 additions
and
1,276 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,61 @@ | ||
import * as httpm from '../_out'; | ||
import * as am from '../_out/auth'; | ||
import * as httpm from '../_out' | ||
import * as am from '../_out/auth' | ||
|
||
describe('auth', () => { | ||
beforeEach(() => { | ||
beforeEach(() => {}) | ||
|
||
}) | ||
|
||
afterEach(() => { | ||
afterEach(() => {}) | ||
|
||
}) | ||
|
||
it('does basic http get request with basic auth', async() => { | ||
let bh: am.BasicCredentialHandler = new am.BasicCredentialHandler('johndoe', 'password'); | ||
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [bh]); | ||
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get'); | ||
expect(res.message.statusCode).toBe(200); | ||
let body: string = await res.readBody(); | ||
let obj:any = JSON.parse(body); | ||
let auth: string = obj.headers.Authorization; | ||
let creds: string = Buffer.from(auth.substring('Basic '.length), 'base64').toString(); | ||
expect(creds).toBe('johndoe:password'); | ||
expect(obj.url).toBe("http://httpbin.org/get"); | ||
}); | ||
it('does basic http get request with basic auth', async () => { | ||
let bh: am.BasicCredentialHandler = new am.BasicCredentialHandler( | ||
'johndoe', | ||
'password' | ||
) | ||
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [bh]) | ||
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get') | ||
expect(res.message.statusCode).toBe(200) | ||
let body: string = await res.readBody() | ||
let obj: any = JSON.parse(body) | ||
let auth: string = obj.headers.Authorization | ||
let creds: string = Buffer.from( | ||
auth.substring('Basic '.length), | ||
'base64' | ||
).toString() | ||
expect(creds).toBe('johndoe:password') | ||
expect(obj.url).toBe('http://httpbin.org/get') | ||
}) | ||
|
||
it('does basic http get request with pat token auth', async() => { | ||
let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs'; | ||
let ph: am.PersonalAccessTokenCredentialHandler = | ||
new am.PersonalAccessTokenCredentialHandler(token); | ||
it('does basic http get request with pat token auth', async () => { | ||
let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs' | ||
let ph: am.PersonalAccessTokenCredentialHandler = new am.PersonalAccessTokenCredentialHandler( | ||
token | ||
) | ||
|
||
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]); | ||
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get'); | ||
expect(res.message.statusCode).toBe(200); | ||
let body: string = await res.readBody(); | ||
let obj:any = JSON.parse(body); | ||
let auth: string = obj.headers.Authorization; | ||
let creds: string = Buffer.from(auth.substring('Basic '.length), 'base64').toString(); | ||
expect(creds).toBe('PAT:' + token); | ||
expect(obj.url).toBe("http://httpbin.org/get"); | ||
}); | ||
|
||
it('does basic http get request with pat token auth', async() => { | ||
let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs'; | ||
let ph: am.BearerCredentialHandler = | ||
new am.BearerCredentialHandler(token); | ||
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]) | ||
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get') | ||
expect(res.message.statusCode).toBe(200) | ||
let body: string = await res.readBody() | ||
let obj: any = JSON.parse(body) | ||
let auth: string = obj.headers.Authorization | ||
let creds: string = Buffer.from( | ||
auth.substring('Basic '.length), | ||
'base64' | ||
).toString() | ||
expect(creds).toBe('PAT:' + token) | ||
expect(obj.url).toBe('http://httpbin.org/get') | ||
}) | ||
|
||
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]); | ||
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get'); | ||
expect(res.message.statusCode).toBe(200); | ||
let body: string = await res.readBody(); | ||
let obj:any = JSON.parse(body); | ||
let auth: string = obj.headers.Authorization; | ||
expect(auth).toBe('Bearer ' + token); | ||
expect(obj.url).toBe("http://httpbin.org/get"); | ||
}); | ||
it('does basic http get request with pat token auth', async () => { | ||
let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs' | ||
let ph: am.BearerCredentialHandler = new am.BearerCredentialHandler(token) | ||
|
||
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]) | ||
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get') | ||
expect(res.message.statusCode).toBe(200) | ||
let body: string = await res.readBody() | ||
let obj: any = JSON.parse(body) | ||
let auth: string = obj.headers.Authorization | ||
expect(auth).toBe('Bearer ' + token) | ||
expect(obj.url).toBe('http://httpbin.org/get') | ||
}) | ||
}) |
Oops, something went wrong.