Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7e08af9b5 |
Generated
+4
-5
@@ -4925,13 +4925,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.7.4",
|
"version": "1.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz",
|
||||||
"integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==",
|
"integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.6",
|
"follow-redirects": "^1.15.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"proxy-from-env": "^1.1.0"
|
"proxy-from-env": "^1.1.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,6 @@ export type AttestOptions = {
|
|||||||
// Sigstore instance to use for signing. Must be one of "public-good" or
|
// Sigstore instance to use for signing. Must be one of "public-good" or
|
||||||
// "github".
|
// "github".
|
||||||
sigstore?: 'public-good' | 'github'
|
sigstore?: 'public-good' | 'github'
|
||||||
// HTTP headers to include in request to attestations API.
|
|
||||||
headers?: {[header: string]: string | number | undefined}
|
|
||||||
// Whether to skip writing the attestation to the GH attestations API.
|
// Whether to skip writing the attestation to the GH attestations API.
|
||||||
skipWrite?: boolean
|
skipWrite?: boolean
|
||||||
}
|
}
|
||||||
@@ -115,8 +113,6 @@ export type AttestProvenanceOptions = {
|
|||||||
// Sigstore instance to use for signing. Must be one of "public-good" or
|
// Sigstore instance to use for signing. Must be one of "public-good" or
|
||||||
// "github".
|
// "github".
|
||||||
sigstore?: 'public-good' | 'github'
|
sigstore?: 'public-good' | 'github'
|
||||||
// HTTP headers to include in request to attestations API.
|
|
||||||
headers?: {[header: string]: string | number | undefined}
|
|
||||||
// Whether to skip writing the attestation to the GH attestations API.
|
// Whether to skip writing the attestation to the GH attestations API.
|
||||||
skipWrite?: boolean
|
skipWrite?: boolean
|
||||||
// Issuer URL responsible for minting the OIDC token from which the
|
// Issuer URL responsible for minting the OIDC token from which the
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
# @actions/attest Releases
|
# @actions/attest Releases
|
||||||
|
|
||||||
### 1.4.0
|
|
||||||
|
|
||||||
- Add new `headers` parameter to the `attest` and `attestProvenance` functions.
|
|
||||||
|
|
||||||
### 1.3.1
|
### 1.3.1
|
||||||
|
|
||||||
- Fix bug with proxy support when retrieving JWKS for OIDC issuer
|
- Fix bug with proxy support when retrieving JWKS for OIDC issuer
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {getIDTokenClaims} from '../src/oidc'
|
|||||||
|
|
||||||
describe('getIDTokenClaims', () => {
|
describe('getIDTokenClaims', () => {
|
||||||
const originalEnv = process.env
|
const originalEnv = process.env
|
||||||
const issuer = 'https://example.com'
|
const issuer = 'https://token.actions.example.ghe.com'
|
||||||
const audience = 'nobody'
|
const audience = 'nobody'
|
||||||
const requestToken = 'token'
|
const requestToken = 'token'
|
||||||
const openidConfigPath = '/.well-known/openid-configuration'
|
const openidConfigPath = '/.well-known/openid-configuration'
|
||||||
@@ -63,7 +63,7 @@ describe('getIDTokenClaims', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns the ID token claims', async () => {
|
it('returns the ID token claims', async () => {
|
||||||
const result = await getIDTokenClaims(issuer)
|
const result = await getIDTokenClaims()
|
||||||
expect(result).toEqual(claims)
|
expect(result).toEqual(claims)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -83,7 +83,7 @@ describe('getIDTokenClaims', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
await expect(getIDTokenClaims(issuer)).rejects.toThrow(/missing claims/i)
|
await expect(getIDTokenClaims()).rejects.toThrow(/missing claims/i)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ describe('getIDTokenClaims', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
await expect(getIDTokenClaims(issuer)).rejects.toThrow(/unexpected "iss"/)
|
await expect(getIDTokenClaims()).rejects.toThrow(/issuer mismatch/i)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ describe('getIDTokenClaims', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('throw an error', async () => {
|
it('throw an error', async () => {
|
||||||
await expect(getIDTokenClaims(issuer)).rejects.toThrow(/unexpected "aud"/)
|
await expect(getIDTokenClaims()).rejects.toThrow(/verification failed/i)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -140,9 +140,7 @@ describe('getIDTokenClaims', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
await expect(getIDTokenClaims(issuer)).rejects.toThrow(
|
await expect(getIDTokenClaims()).rejects.toThrow(/failed to get id/i)
|
||||||
/failed to get id/i
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {attestProvenance, buildSLSAProvenancePredicate} from '../src/provenance'
|
|||||||
|
|
||||||
describe('provenance functions', () => {
|
describe('provenance functions', () => {
|
||||||
const originalEnv = process.env
|
const originalEnv = process.env
|
||||||
const issuer = 'https://example.com'
|
const issuer = 'https://token.actions.githubusercontent.com'
|
||||||
const audience = 'nobody'
|
const audience = 'nobody'
|
||||||
const jwksPath = '/.well-known/jwks.json'
|
const jwksPath = '/.well-known/jwks.json'
|
||||||
const tokenPath = '/token'
|
const tokenPath = '/token'
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ describe('writeAttestation', () => {
|
|||||||
const originalEnv = process.env
|
const originalEnv = process.env
|
||||||
const attestation = {foo: 'bar '}
|
const attestation = {foo: 'bar '}
|
||||||
const token = 'token'
|
const token = 'token'
|
||||||
const headers = {'X-GitHub-Foo': 'true'}
|
|
||||||
|
|
||||||
const mockAgent = new MockAgent()
|
const mockAgent = new MockAgent()
|
||||||
setGlobalDispatcher(mockAgent)
|
setGlobalDispatcher(mockAgent)
|
||||||
@@ -28,16 +27,14 @@ describe('writeAttestation', () => {
|
|||||||
.intercept({
|
.intercept({
|
||||||
path: '/repos/foo/bar/attestations',
|
path: '/repos/foo/bar/attestations',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {authorization: `token ${token}`, ...headers},
|
headers: {authorization: `token ${token}`},
|
||||||
body: JSON.stringify({bundle: attestation})
|
body: JSON.stringify({bundle: attestation})
|
||||||
})
|
})
|
||||||
.reply(201, {id: '123'})
|
.reply(201, {id: '123'})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('persists the attestation', async () => {
|
it('persists the attestation', async () => {
|
||||||
await expect(
|
await expect(writeAttestation(attestation, token)).resolves.toEqual('123')
|
||||||
writeAttestation(attestation, token, {headers})
|
|
||||||
).resolves.toEqual('123')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/attest",
|
"name": "@actions/attest",
|
||||||
"version": "1.4.0",
|
"version": "1.3.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@actions/attest",
|
"name": "@actions/attest",
|
||||||
"version": "1.4.0",
|
"version": "1.3.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/attest",
|
"name": "@actions/attest",
|
||||||
"version": "1.4.0",
|
"version": "1.3.1",
|
||||||
"description": "Actions attestation lib",
|
"description": "Actions attestation lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ export type AttestOptions = {
|
|||||||
// Sigstore instance to use for signing. Must be one of "public-good" or
|
// Sigstore instance to use for signing. Must be one of "public-good" or
|
||||||
// "github".
|
// "github".
|
||||||
sigstore?: SigstoreInstance
|
sigstore?: SigstoreInstance
|
||||||
// HTTP headers to include in request to attestations API.
|
|
||||||
headers?: {[header: string]: string | number | undefined}
|
|
||||||
// Whether to skip writing the attestation to the GH attestations API.
|
// Whether to skip writing the attestation to the GH attestations API.
|
||||||
skipWrite?: boolean
|
skipWrite?: boolean
|
||||||
}
|
}
|
||||||
@@ -63,11 +61,7 @@ export async function attest(options: AttestOptions): Promise<Attestation> {
|
|||||||
// Store the attestation
|
// Store the attestation
|
||||||
let attestationID: string | undefined
|
let attestationID: string | undefined
|
||||||
if (options.skipWrite !== true) {
|
if (options.skipWrite !== true) {
|
||||||
attestationID = await writeAttestation(
|
attestationID = await writeAttestation(bundleToJSON(bundle), options.token)
|
||||||
bundleToJSON(bundle),
|
|
||||||
options.token,
|
|
||||||
{headers: options.headers}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return toAttestation(bundle, attestationID)
|
return toAttestation(bundle, attestationID)
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ import {getIDToken} from '@actions/core'
|
|||||||
import {HttpClient} from '@actions/http-client'
|
import {HttpClient} from '@actions/http-client'
|
||||||
import * as jose from 'jose'
|
import * as jose from 'jose'
|
||||||
|
|
||||||
|
const VALID_ISSUERS = [
|
||||||
|
'https://token.actions.githubusercontent.com',
|
||||||
|
new RegExp('^https://token\\.actions\\.[a-z0-9-]+\\.ghe\\.com$')
|
||||||
|
] as const
|
||||||
|
|
||||||
const OIDC_AUDIENCE = 'nobody'
|
const OIDC_AUDIENCE = 'nobody'
|
||||||
|
|
||||||
const REQUIRED_CLAIMS = [
|
const REQUIRED_CLAIMS = [
|
||||||
@@ -25,10 +30,10 @@ type OIDCConfig = {
|
|||||||
jwks_uri: string
|
jwks_uri: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getIDTokenClaims = async (issuer: string): Promise<ClaimSet> => {
|
export const getIDTokenClaims = async (): Promise<ClaimSet> => {
|
||||||
try {
|
try {
|
||||||
const token = await getIDToken(OIDC_AUDIENCE)
|
const token = await getIDToken(OIDC_AUDIENCE)
|
||||||
const claims = await decodeOIDCToken(token, issuer)
|
const claims = await decodeOIDCToken(token)
|
||||||
assertClaimSet(claims)
|
assertClaimSet(claims)
|
||||||
return claims
|
return claims
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -36,15 +41,24 @@ export const getIDTokenClaims = async (issuer: string): Promise<ClaimSet> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodeOIDCToken = async (
|
const decodeOIDCToken = async (token: string): Promise<jose.JWTPayload> => {
|
||||||
token: string,
|
// Decode is an unsafe operation (no signature verification) but we're
|
||||||
issuer: string
|
// verifying the signature below after retrieving the issuer.
|
||||||
): Promise<jose.JWTPayload> => {
|
const {iss} = jose.decodeJwt(token)
|
||||||
|
|
||||||
|
if (!iss) {
|
||||||
|
throw new Error('No issuer found')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issuer must match at least one of the valid issuers
|
||||||
|
if (!VALID_ISSUERS.some(allowed => iss.match(allowed))) {
|
||||||
|
throw new Error('Issuer mismatch')
|
||||||
|
}
|
||||||
|
|
||||||
// Verify and decode token
|
// Verify and decode token
|
||||||
const jwks = jose.createLocalJWKSet(await getJWKS(issuer))
|
const jwks = jose.createLocalJWKSet(await getJWKS(iss))
|
||||||
const {payload} = await jose.jwtVerify(token, jwks, {
|
const {payload} = await jose.jwtVerify(token, jwks, {
|
||||||
audience: OIDC_AUDIENCE,
|
audience: OIDC_AUDIENCE
|
||||||
issuer
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const buildSLSAProvenancePredicate = async (
|
|||||||
issuer: string = DEFAULT_ISSUER
|
issuer: string = DEFAULT_ISSUER
|
||||||
): Promise<Predicate> => {
|
): Promise<Predicate> => {
|
||||||
const serverURL = process.env.GITHUB_SERVER_URL
|
const serverURL = process.env.GITHUB_SERVER_URL
|
||||||
const claims = await getIDTokenClaims(issuer)
|
const claims = await getIDTokenClaims()
|
||||||
|
|
||||||
// Split just the path and ref from the workflow string.
|
// Split just the path and ref from the workflow string.
|
||||||
// owner/repo/.github/workflows/main.yml@main =>
|
// owner/repo/.github/workflows/main.yml@main =>
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {retry} from '@octokit/plugin-retry'
|
import {retry} from '@octokit/plugin-retry'
|
||||||
import {RequestHeaders} from '@octokit/types'
|
|
||||||
|
|
||||||
const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
|
const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
|
||||||
const DEFAULT_RETRY_COUNT = 5
|
const DEFAULT_RETRY_COUNT = 5
|
||||||
|
|
||||||
export type WriteOptions = {
|
export type WriteOptions = {
|
||||||
retry?: number
|
retry?: number
|
||||||
headers?: RequestHeaders
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Writes an attestation to the repository's attestations endpoint.
|
* Writes an attestation to the repository's attestations endpoint.
|
||||||
@@ -28,7 +26,6 @@ export const writeAttestation = async (
|
|||||||
const response = await octokit.request(CREATE_ATTESTATION_REQUEST, {
|
const response = await octokit.request(CREATE_ATTESTATION_REQUEST, {
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
headers: options.headers,
|
|
||||||
data: {bundle: attestation}
|
data: {bundle: attestation}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
# @actions/glob Releases
|
# @actions/glob Releases
|
||||||
|
|
||||||
### 0.5.0
|
|
||||||
- Added `excludeHiddenFiles` option, which is disabled by default to preserve existing behavior [#1791: Add glob option to ignore hidden files](https://github.com/actions/toolkit/pull/1791)
|
|
||||||
|
|
||||||
### 0.4.0
|
### 0.4.0
|
||||||
- Pass in the current workspace as a parameter to HashFiles [#1318](https://github.com/actions/toolkit/pull/1318)
|
- Pass in the current workspace as a parameter to HashFiles [#1318](https://github.com/actions/toolkit/pull/1318)
|
||||||
|
|
||||||
|
|||||||
@@ -708,7 +708,7 @@ describe('globber', () => {
|
|||||||
expect(itemPaths).toEqual([])
|
expect(itemPaths).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns hidden files by default', async () => {
|
it('returns hidden files', async () => {
|
||||||
// Create the following layout:
|
// Create the following layout:
|
||||||
// <root>
|
// <root>
|
||||||
// <root>/.emptyFolder
|
// <root>/.emptyFolder
|
||||||
@@ -734,26 +734,6 @@ describe('globber', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ignores hidden files when excludeHiddenFiles is set', async () => {
|
|
||||||
// Create the following layout:
|
|
||||||
// <root>
|
|
||||||
// <root>/.emptyFolder
|
|
||||||
// <root>/.file
|
|
||||||
// <root>/.folder
|
|
||||||
// <root>/.folder/file
|
|
||||||
const root = path.join(getTestTemp(), 'ignores-hidden-files')
|
|
||||||
await createHiddenDirectory(path.join(root, '.emptyFolder'))
|
|
||||||
await createHiddenDirectory(path.join(root, '.folder'))
|
|
||||||
await createHiddenFile(path.join(root, '.file'), 'test .file content')
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(root, '.folder', 'file'),
|
|
||||||
'test .folder/file content'
|
|
||||||
)
|
|
||||||
|
|
||||||
const itemPaths = await glob(root, {excludeHiddenFiles: true})
|
|
||||||
expect(itemPaths).toEqual([root])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns normalized paths', async () => {
|
it('returns normalized paths', async () => {
|
||||||
// Create the following layout:
|
// Create the following layout:
|
||||||
// <root>/hello/world.txt
|
// <root>/hello/world.txt
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/glob",
|
"name": "@actions/glob",
|
||||||
"version": "0.5.0",
|
"version": "0.4.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"description": "Actions glob lib",
|
"description": "Actions glob lib",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/glob",
|
"name": "@actions/glob",
|
||||||
"version": "0.5.0",
|
"version": "0.4.0",
|
||||||
"preview": true,
|
"preview": true,
|
||||||
"description": "Actions glob lib",
|
"description": "Actions glob lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
|
|||||||
followSymbolicLinks: true,
|
followSymbolicLinks: true,
|
||||||
implicitDescendants: true,
|
implicitDescendants: true,
|
||||||
matchDirectories: true,
|
matchDirectories: true,
|
||||||
omitBrokenSymbolicLinks: true,
|
omitBrokenSymbolicLinks: true
|
||||||
excludeHiddenFiles: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
@@ -33,11 +32,6 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
|
|||||||
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
|
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
|
||||||
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
|
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof copy.excludeHiddenFiles === 'boolean') {
|
|
||||||
result.excludeHiddenFiles = copy.excludeHiddenFiles
|
|
||||||
core.debug(`excludeHiddenFiles '${result.excludeHiddenFiles}'`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -36,13 +36,4 @@ export interface GlobOptions {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
omitBrokenSymbolicLinks?: boolean
|
omitBrokenSymbolicLinks?: boolean
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether to exclude hidden files (files and directories starting with a `.`).
|
|
||||||
* This does not apply to Windows files and directories with the hidden attribute unless
|
|
||||||
* they are also prefixed with a `.`.
|
|
||||||
*
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
excludeHiddenFiles?: boolean
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,11 +128,6 @@ export class DefaultGlobber implements Globber {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hidden file or directory?
|
|
||||||
if (options.excludeHiddenFiles && path.basename(item.path).match(/^\./)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Directory
|
// Directory
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
// Matched
|
// Matched
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ describe('basics', () => {
|
|||||||
// "user-agent": "typed-test-client-tests"
|
// "user-agent": "typed-test-client-tests"
|
||||||
// },
|
// },
|
||||||
// "origin": "173.95.152.44",
|
// "origin": "173.95.152.44",
|
||||||
// "url": "http://postman-echo.com/get"
|
// "url": "https://postman-echo.com/get"
|
||||||
// }
|
// }
|
||||||
|
|
||||||
it('does basic http get request', async () => {
|
it('does basic http get request', async () => {
|
||||||
@@ -63,17 +63,16 @@ describe('basics', () => {
|
|||||||
expect(obj.headers['user-agent']).toBeFalsy()
|
expect(obj.headers['user-agent']).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
/* TODO write a mock rather then relying on a third party
|
|
||||||
it('does basic https get request', async () => {
|
it('does basic https get request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
it('does basic http get request with default headers', async () => {
|
it('does basic http get request with default headers', async () => {
|
||||||
const http: httpm.HttpClient = new httpm.HttpClient(
|
const http: httpm.HttpClient = new httpm.HttpClient(
|
||||||
'http-client-tests',
|
'http-client-tests',
|
||||||
@@ -126,12 +125,12 @@ describe('basics', () => {
|
|||||||
it('pipes a get request', async () => {
|
it('pipes a get request', async () => {
|
||||||
return new Promise<void>(async resolve => {
|
return new Promise<void>(async resolve => {
|
||||||
const file = fs.createWriteStream(sampleFilePath)
|
const file = fs.createWriteStream(sampleFilePath)
|
||||||
;(await _http.get('http://postman-echo.com/get')).message
|
;(await _http.get('https://postman-echo.com/get')).message
|
||||||
.pipe(file)
|
.pipe(file)
|
||||||
.on('close', () => {
|
.on('close', () => {
|
||||||
const body: string = fs.readFileSync(sampleFilePath).toString()
|
const body: string = fs.readFileSync(sampleFilePath).toString()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -139,32 +138,32 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('does basic get request with redirects', async () => {
|
it('does basic get request with redirects', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)}`
|
)}`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic get request with redirects (303)', async () => {
|
it('does basic get request with redirects (303)', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)}&status_code=303`
|
)}&status_code=303`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns 404 for not found get request on redirect', async () => {
|
it('returns 404 for not found get request on redirect', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/status/404'
|
'https://postman-echo.com/status/404'
|
||||||
)}&status_code=303`
|
)}&status_code=303`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(404)
|
expect(res.message.statusCode).toBe(404)
|
||||||
@@ -178,8 +177,8 @@ describe('basics', () => {
|
|||||||
{allowRedirects: false}
|
{allowRedirects: false}
|
||||||
)
|
)
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)}`
|
)}`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(302)
|
expect(res.message.statusCode).toBe(302)
|
||||||
@@ -192,8 +191,8 @@ describe('basics', () => {
|
|||||||
authorization: 'shhh'
|
authorization: 'shhh'
|
||||||
}
|
}
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://www.postman-echo.com/get'
|
'https://www.postman-echo.com/get'
|
||||||
)}`,
|
)}`,
|
||||||
headers
|
headers
|
||||||
)
|
)
|
||||||
@@ -205,7 +204,7 @@ describe('basics', () => {
|
|||||||
expect(obj.headers[httpm.Headers.Accept]).toBe('application/json')
|
expect(obj.headers[httpm.Headers.Accept]).toBe('application/json')
|
||||||
expect(obj.headers['Authorization']).toBeUndefined()
|
expect(obj.headers['Authorization']).toBeUndefined()
|
||||||
expect(obj.headers['authorization']).toBeUndefined()
|
expect(obj.headers['authorization']).toBeUndefined()
|
||||||
expect(obj.url).toBe('http://www.postman-echo.com/get')
|
expect(obj.url).toBe('https://www.postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not pass Auth with diff hostname redirects', async () => {
|
it('does not pass Auth with diff hostname redirects', async () => {
|
||||||
@@ -214,8 +213,8 @@ describe('basics', () => {
|
|||||||
Authorization: 'shhh'
|
Authorization: 'shhh'
|
||||||
}
|
}
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://www.postman-echo.com/get'
|
'https://www.postman-echo.com/get'
|
||||||
)}`,
|
)}`,
|
||||||
headers
|
headers
|
||||||
)
|
)
|
||||||
@@ -227,7 +226,7 @@ describe('basics', () => {
|
|||||||
expect(obj.headers[httpm.Headers.Accept]).toBe('application/json')
|
expect(obj.headers[httpm.Headers.Accept]).toBe('application/json')
|
||||||
expect(obj.headers['Authorization']).toBeUndefined()
|
expect(obj.headers['Authorization']).toBeUndefined()
|
||||||
expect(obj.headers['authorization']).toBeUndefined()
|
expect(obj.headers['authorization']).toBeUndefined()
|
||||||
expect(obj.url).toBe('http://www.postman-echo.com/get')
|
expect(obj.url).toBe('https://www.postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic head request', async () => {
|
it('does basic head request', async () => {
|
||||||
@@ -290,11 +289,11 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('gets a json object', async () => {
|
it('gets a json object', async () => {
|
||||||
const jsonObj = await _http.getJson<HttpBinData>(
|
const jsonObj = await _http.getJson<HttpBinData>(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(jsonObj.statusCode).toBe(200)
|
expect(jsonObj.statusCode).toBe(200)
|
||||||
expect(jsonObj.result).toBeDefined()
|
expect(jsonObj.result).toBeDefined()
|
||||||
expect(jsonObj.result?.url).toBe('http://postman-echo.com/get')
|
expect(jsonObj.result?.url).toBe('https://postman-echo.com/get')
|
||||||
expect(jsonObj.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(jsonObj.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
)
|
)
|
||||||
@@ -305,7 +304,7 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('getting a non existent json object returns null', async () => {
|
it('getting a non existent json object returns null', async () => {
|
||||||
const jsonObj = await _http.getJson<HttpBinData>(
|
const jsonObj = await _http.getJson<HttpBinData>(
|
||||||
'http://postman-echo.com/status/404'
|
'https://postman-echo.com/status/404'
|
||||||
)
|
)
|
||||||
expect(jsonObj.statusCode).toBe(404)
|
expect(jsonObj.statusCode).toBe(404)
|
||||||
expect(jsonObj.result).toBeNull()
|
expect(jsonObj.result).toBeNull()
|
||||||
@@ -314,12 +313,12 @@ describe('basics', () => {
|
|||||||
it('posts a json object', async () => {
|
it('posts a json object', async () => {
|
||||||
const res = {name: 'foo'}
|
const res = {name: 'foo'}
|
||||||
const restRes = await _http.postJson<HttpBinData>(
|
const restRes = await _http.postJson<HttpBinData>(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
res
|
res
|
||||||
)
|
)
|
||||||
expect(restRes.statusCode).toBe(200)
|
expect(restRes.statusCode).toBe(200)
|
||||||
expect(restRes.result).toBeDefined()
|
expect(restRes.result).toBeDefined()
|
||||||
expect(restRes.result?.url).toBe('http://postman-echo.com/post')
|
expect(restRes.result?.url).toBe('https://postman-echo.com/post')
|
||||||
expect(restRes.result?.json.name).toBe('foo')
|
expect(restRes.result?.json.name).toBe('foo')
|
||||||
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
@@ -335,12 +334,12 @@ describe('basics', () => {
|
|||||||
it('puts a json object', async () => {
|
it('puts a json object', async () => {
|
||||||
const res = {name: 'foo'}
|
const res = {name: 'foo'}
|
||||||
const restRes = await _http.putJson<HttpBinData>(
|
const restRes = await _http.putJson<HttpBinData>(
|
||||||
'http://postman-echo.com/put',
|
'https://postman-echo.com/put',
|
||||||
res
|
res
|
||||||
)
|
)
|
||||||
expect(restRes.statusCode).toBe(200)
|
expect(restRes.statusCode).toBe(200)
|
||||||
expect(restRes.result).toBeDefined()
|
expect(restRes.result).toBeDefined()
|
||||||
expect(restRes.result?.url).toBe('http://postman-echo.com/put')
|
expect(restRes.result?.url).toBe('https://postman-echo.com/put')
|
||||||
expect(restRes.result?.json.name).toBe('foo')
|
expect(restRes.result?.json.name).toBe('foo')
|
||||||
|
|
||||||
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
@@ -357,12 +356,12 @@ describe('basics', () => {
|
|||||||
it('patch a json object', async () => {
|
it('patch a json object', async () => {
|
||||||
const res = {name: 'foo'}
|
const res = {name: 'foo'}
|
||||||
const restRes = await _http.patchJson<HttpBinData>(
|
const restRes = await _http.patchJson<HttpBinData>(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
res
|
res
|
||||||
)
|
)
|
||||||
expect(restRes.statusCode).toBe(200)
|
expect(restRes.statusCode).toBe(200)
|
||||||
expect(restRes.result).toBeDefined()
|
expect(restRes.result).toBeDefined()
|
||||||
expect(restRes.result?.url).toBe('http://postman-echo.com/patch')
|
expect(restRes.result?.url).toBe('https://postman-echo.com/patch')
|
||||||
expect(restRes.result?.json.name).toBe('foo')
|
expect(restRes.result?.json.name).toBe('foo')
|
||||||
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on getJson', async () => {
|
it('preserves existing headers on getJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.getJson<any>(
|
let jsonObj = await _http.getJson<any>(
|
||||||
'http://postman-echo.com/get',
|
'https://postman-echo.com/get',
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('foo')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('foo')
|
||||||
@@ -26,7 +26,7 @@ describe('headers', () => {
|
|||||||
[httpm.Headers.Accept]: 'baz'
|
[httpm.Headers.Accept]: 'baz'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.getJson<any>('http://postman-echo.com/get')
|
jsonObj = await httpWithHeaders.getJson<any>('https://postman-echo.com/get')
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
expect(jsonObj.headers[httpm.Headers.ContentType]).toContain(
|
expect(jsonObj.headers[httpm.Headers.ContentType]).toContain(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
@@ -36,7 +36,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on postJson', async () => {
|
it('preserves existing headers on postJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.postJson<any>(
|
let jsonObj = await _http.postJson<any>(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
{},
|
{},
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
@@ -52,7 +52,7 @@ describe('headers', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.postJson<any>(
|
jsonObj = await httpWithHeaders.postJson<any>(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
@@ -64,7 +64,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on putJson', async () => {
|
it('preserves existing headers on putJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.putJson<any>(
|
let jsonObj = await _http.putJson<any>(
|
||||||
'http://postman-echo.com/put',
|
'https://postman-echo.com/put',
|
||||||
{},
|
{},
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
@@ -80,7 +80,7 @@ describe('headers', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.putJson<any>(
|
jsonObj = await httpWithHeaders.putJson<any>(
|
||||||
'http://postman-echo.com/put',
|
'https://postman-echo.com/put',
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
@@ -92,7 +92,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on patchJson', async () => {
|
it('preserves existing headers on patchJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.patchJson<any>(
|
let jsonObj = await _http.patchJson<any>(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
{},
|
{},
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
@@ -108,7 +108,7 @@ describe('headers', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.patchJson<any>(
|
jsonObj = await httpWithHeaders.patchJson<any>(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
|
|||||||
@@ -222,33 +222,30 @@ describe('proxy', () => {
|
|||||||
expect(_proxyConnects).toHaveLength(0)
|
expect(_proxyConnects).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO mock this out so we don't rely on a third party
|
|
||||||
/*
|
|
||||||
it('HttpClient does basic https get request through proxy', async () => {
|
it('HttpClient does basic https get request through proxy', async () => {
|
||||||
process.env['https_proxy'] = _proxyUrl
|
process.env['https_proxy'] = _proxyUrl
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await httpClient.get(
|
const res: httpm.HttpClientResponse = await httpClient.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(_proxyConnects).toEqual(['postman-echo.com:443'])
|
expect(_proxyConnects).toEqual(['postman-echo.com:443'])
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
|
|
||||||
it('HttpClient does basic http get request when bypass proxy', async () => {
|
it('HttpClient does basic https get request when bypass proxy', async () => {
|
||||||
process.env['http_proxy'] = _proxyUrl
|
process.env['https_proxy'] = _proxyUrl
|
||||||
process.env['no_proxy'] = 'postman-echo.com'
|
process.env['no_proxy'] = 'postman-echo.com'
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await httpClient.get(
|
const res: httpm.HttpClientResponse = await httpClient.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(_proxyConnects).toHaveLength(0)
|
expect(_proxyConnects).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user