mirror of
https://github.com/actions/toolkit
synced 2025-05-11 09:32:58 +00:00

* fixing audit failures * replacing lerna bootstrap with npm command * audit fix for cache and tool-cache * updating tunnel * upgrading core packages * re-adding tunnel as prod dep * updating dependencies * updating exec deps * updating exec io package * . * Revert * updating packages * adding core as dep * updating learna config * updating lerna commands * Removing audit failing packages in cache + tool-cache * updating contribution bootstrap description * updating libraries * prettier lint * hiding stricter rules * updating prettier command * Removing unknown flag * Adding eslint prettier * ignoring sym links * updating ignore path * updating prettier rules * changing prettier + github ver * updating ts and ignores * Revert ts * Adding unknown ignores * downgrading lerna * . * adding nx * Adding lint auto lint rules * updating eslint ignore for glob packages * Adding subdirs to ignore * adding flag for ignore pattern in linter * Expanding ignore regex * Adding ignore rules * adding another ignore pattern to tsconfig eslint * adding ignore pattern to eslintrc * syncing package-json * updating traverse * . * test adding core and http client to base package * running npm ci * adding tsconfig paths * adding base URL * Adding explicit path to core and http-client * editing tsc call * updating artifact packages * force build * updating lock file version * updating lock file version * upgrading node version * Adding babel traverse back * fixing build issue * fixing typescript ver * updating package json * Adding ignore for artifact test * adding ignore to flags * unlink after test completes * cleanup * merge + package edit
72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
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')
|
|
})
|
|
})
|