|
1 |
| -import * as httpm from '../_out'; |
2 |
| -import * as am from '../_out/auth'; |
| 1 | +import * as httpm from '../_out' |
| 2 | +import * as am from '../_out/auth' |
3 | 3 |
|
4 | 4 | describe('auth', () => {
|
5 |
| - beforeEach(() => { |
| 5 | + beforeEach(() => {}) |
6 | 6 |
|
7 |
| - }) |
8 |
| - |
9 |
| - afterEach(() => { |
| 7 | + afterEach(() => {}) |
10 | 8 |
|
11 |
| - }) |
12 |
| - |
13 |
| - it('does basic http get request with basic auth', async() => { |
14 |
| - let bh: am.BasicCredentialHandler = new am.BasicCredentialHandler('johndoe', 'password'); |
15 |
| - let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [bh]); |
16 |
| - let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get'); |
17 |
| - expect(res.message.statusCode).toBe(200); |
18 |
| - let body: string = await res.readBody(); |
19 |
| - let obj:any = JSON.parse(body); |
20 |
| - let auth: string = obj.headers.Authorization; |
21 |
| - let creds: string = Buffer.from(auth.substring('Basic '.length), 'base64').toString(); |
22 |
| - expect(creds).toBe('johndoe:password'); |
23 |
| - expect(obj.url).toBe("http://httpbin.org/get"); |
24 |
| - }); |
| 9 | + it('does basic http get request with basic auth', async () => { |
| 10 | + let bh: am.BasicCredentialHandler = new am.BasicCredentialHandler( |
| 11 | + 'johndoe', |
| 12 | + 'password' |
| 13 | + ) |
| 14 | + let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [bh]) |
| 15 | + let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get') |
| 16 | + expect(res.message.statusCode).toBe(200) |
| 17 | + let body: string = await res.readBody() |
| 18 | + let obj: any = JSON.parse(body) |
| 19 | + let auth: string = obj.headers.Authorization |
| 20 | + let creds: string = Buffer.from( |
| 21 | + auth.substring('Basic '.length), |
| 22 | + 'base64' |
| 23 | + ).toString() |
| 24 | + expect(creds).toBe('johndoe:password') |
| 25 | + expect(obj.url).toBe('http://httpbin.org/get') |
| 26 | + }) |
25 | 27 |
|
26 |
| - it('does basic http get request with pat token auth', async() => { |
27 |
| - let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs'; |
28 |
| - let ph: am.PersonalAccessTokenCredentialHandler = |
29 |
| - new am.PersonalAccessTokenCredentialHandler(token); |
| 28 | + it('does basic http get request with pat token auth', async () => { |
| 29 | + let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs' |
| 30 | + let ph: am.PersonalAccessTokenCredentialHandler = new am.PersonalAccessTokenCredentialHandler( |
| 31 | + token |
| 32 | + ) |
30 | 33 |
|
31 |
| - let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]); |
32 |
| - let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get'); |
33 |
| - expect(res.message.statusCode).toBe(200); |
34 |
| - let body: string = await res.readBody(); |
35 |
| - let obj:any = JSON.parse(body); |
36 |
| - let auth: string = obj.headers.Authorization; |
37 |
| - let creds: string = Buffer.from(auth.substring('Basic '.length), 'base64').toString(); |
38 |
| - expect(creds).toBe('PAT:' + token); |
39 |
| - expect(obj.url).toBe("http://httpbin.org/get"); |
40 |
| - }); |
41 |
| - |
42 |
| - it('does basic http get request with pat token auth', async() => { |
43 |
| - let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs'; |
44 |
| - let ph: am.BearerCredentialHandler = |
45 |
| - new am.BearerCredentialHandler(token); |
| 34 | + let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]) |
| 35 | + let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get') |
| 36 | + expect(res.message.statusCode).toBe(200) |
| 37 | + let body: string = await res.readBody() |
| 38 | + let obj: any = JSON.parse(body) |
| 39 | + let auth: string = obj.headers.Authorization |
| 40 | + let creds: string = Buffer.from( |
| 41 | + auth.substring('Basic '.length), |
| 42 | + 'base64' |
| 43 | + ).toString() |
| 44 | + expect(creds).toBe('PAT:' + token) |
| 45 | + expect(obj.url).toBe('http://httpbin.org/get') |
| 46 | + }) |
46 | 47 |
|
47 |
| - let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]); |
48 |
| - let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get'); |
49 |
| - expect(res.message.statusCode).toBe(200); |
50 |
| - let body: string = await res.readBody(); |
51 |
| - let obj:any = JSON.parse(body); |
52 |
| - let auth: string = obj.headers.Authorization; |
53 |
| - expect(auth).toBe('Bearer ' + token); |
54 |
| - expect(obj.url).toBe("http://httpbin.org/get"); |
55 |
| - }); |
| 48 | + it('does basic http get request with pat token auth', async () => { |
| 49 | + let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs' |
| 50 | + let ph: am.BearerCredentialHandler = new am.BearerCredentialHandler(token) |
| 51 | + |
| 52 | + let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]) |
| 53 | + let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get') |
| 54 | + expect(res.message.statusCode).toBe(200) |
| 55 | + let body: string = await res.readBody() |
| 56 | + let obj: any = JSON.parse(body) |
| 57 | + let auth: string = obj.headers.Authorization |
| 58 | + expect(auth).toBe('Bearer ' + token) |
| 59 | + expect(obj.url).toBe('http://httpbin.org/get') |
| 60 | + }) |
56 | 61 | })
|
0 commit comments