forked from actions/toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.test.ts
72 lines (65 loc) · 2.38 KB
/
auth.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as httpm from '../lib'
import * as am from '../lib/auth'
describe('auth', () => {
beforeEach(() => {})
afterEach(() => {})
it('does basic http get request with basic auth', async () => {
const bh: am.BasicCredentialHandler = new am.BasicCredentialHandler(
'johndoe',
'password'
)
const http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [
bh
])
const res: httpm.HttpClientResponse = await http.get(
'http://postman-echo.com/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
const auth: string = obj.headers.authorization
const creds: string = Buffer.from(
auth.substring('Basic '.length),
'base64'
).toString()
expect(creds).toBe('johndoe:password')
expect(obj.url).toBe('http://postman-echo.com/get')
})
it('does basic http get request with pat token auth', async () => {
const token = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs'
const ph: am.PersonalAccessTokenCredentialHandler =
new am.PersonalAccessTokenCredentialHandler(token)
const http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [
ph
])
const res: httpm.HttpClientResponse = await http.get(
'http://postman-echo.com/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
const auth: string = obj.headers.authorization
const creds: string = Buffer.from(
auth.substring('Basic '.length),
'base64'
).toString()
expect(creds).toBe(`PAT:${token}`)
expect(obj.url).toBe('http://postman-echo.com/get')
})
it('does basic http get request with pat token auth', async () => {
const token = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs'
const ph: am.BearerCredentialHandler = new am.BearerCredentialHandler(token)
const http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [
ph
])
const res: httpm.HttpClientResponse = await http.get(
'http://postman-echo.com/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
const auth: string = obj.headers.authorization
expect(auth).toBe(`Bearer ${token}`)
expect(obj.url).toBe('http://postman-echo.com/get')
})
})