mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-12-02 14:59:03 +00:00
Compare commits
2
Commits
v3
...
v3.4.0-beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
305e4aec4e | ||
|
|
8240f10d3a |
No files matched your search
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "3.3.0"
|
||||
".": "3.4.0-beta"
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [3.4.0-beta](https://github.com/actions/create-github-app-token/compare/v3.3.0...v3.4.0-beta) (2026-11-17)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support GitHub Actions OIDC authentication ([#411](https://github.com/actions/create-github-app-token/issues/411)) ([8240f10](https://github.com/actions/create-github-app-token/commit/8240f10d3ae05b4d450da83e8e247111a36eaf2c))
|
||||
|
||||
## [3.3.0](https://github.com/actions/create-github-app-token/compare/v3.2.0...v3.3.0) (2026-10-12)
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ inputs:
|
||||
required: false
|
||||
deprecationMessage: "Use 'client-id' instead."
|
||||
private-key:
|
||||
description: "GitHub App private key"
|
||||
required: true
|
||||
description: "GitHub App private key. If omitted, authenticate using GitHub Actions OIDC (requires client-id and id-token: write, and a private app owned by the workflow repository's organization)."
|
||||
required: false
|
||||
owner:
|
||||
description: "The owner of the GitHub App installation (defaults to current repository owner)"
|
||||
required: false
|
||||
|
||||
Vendored
+41
-6
@@ -23991,17 +23991,47 @@ async function pRetry(input, options = {}) {
|
||||
throw new Error("Retry attempts exhausted without throwing an error.");
|
||||
}
|
||||
|
||||
// lib/create-oidc-auth.js
|
||||
async function createOidcAuth(clientId, core, request2) {
|
||||
const audience = `${process.env.GITHUB_SERVER_URL || "https://github.com"}/login/oauth`;
|
||||
const token = await core.getIDToken(audience);
|
||||
const auth5 = async ({ installationId, repositoryNames, permissions }) => {
|
||||
const { data } = await request2(
|
||||
"POST /app/installations/{installation_id}/access_tokens{?client_id}",
|
||||
{
|
||||
installation_id: installationId,
|
||||
client_id: clientId,
|
||||
repositories: repositoryNames,
|
||||
permissions,
|
||||
headers: { authorization: `Bearer ${token}` }
|
||||
}
|
||||
);
|
||||
return { token: data.token, expiresAt: data.expires_at };
|
||||
};
|
||||
auth5.hook = (hookRequest, route, parameters) => {
|
||||
const endpoint2 = hookRequest.endpoint(route, parameters);
|
||||
const url = new URL(endpoint2.url);
|
||||
url.searchParams.set("client_id", clientId);
|
||||
endpoint2.url = url.toString();
|
||||
endpoint2.headers.authorization = `Bearer ${token}`;
|
||||
return hookRequest(endpoint2);
|
||||
};
|
||||
return auth5;
|
||||
}
|
||||
|
||||
// lib/main.js
|
||||
async function main(clientId, privateKey, enterprise, owner, repositories, permissions, core, createAppAuth2, request2, skipTokenRevoke) {
|
||||
if (enterprise && (owner || repositories.length > 0)) {
|
||||
throw new Error("Cannot use 'enterprise' input with 'owner' or 'repositories' inputs");
|
||||
}
|
||||
if (enterprise && !privateKey) {
|
||||
throw new Error("The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.");
|
||||
}
|
||||
const target = resolveInstallationTarget(enterprise, owner, repositories, core);
|
||||
const auth5 = createAppAuth2({
|
||||
appId: clientId,
|
||||
privateKey,
|
||||
request: request2
|
||||
});
|
||||
if (!privateKey) {
|
||||
core.info("No 'private-key' provided; authenticating with GitHub Actions OIDC.");
|
||||
}
|
||||
const auth5 = privateKey ? createAppAuth2({ appId: clientId, privateKey, request: request2 }) : await createOidcAuth(clientId, core, request2);
|
||||
const { authentication, installationId, appSlug } = await pRetry(
|
||||
() => getTokenFromTarget(request2, auth5, target, permissions),
|
||||
createTokenRetryOptions(core, getTokenRetryDescription(target))
|
||||
@@ -24222,7 +24252,12 @@ async function run() {
|
||||
}
|
||||
const privateKey = getInput("private-key");
|
||||
if (!privateKey) {
|
||||
throw new Error("The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.");
|
||||
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_URL || !process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) {
|
||||
throw new Error("The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.");
|
||||
}
|
||||
if (!getInput("client-id")) {
|
||||
throw new Error("The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.");
|
||||
}
|
||||
}
|
||||
const enterprise = getInput("enterprise");
|
||||
const owner = getInput("owner");
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Creates an auth strategy compatible with `@octokit/auth-app` that authenticates
|
||||
* as a GitHub App using a GitHub Actions OIDC token instead of a private key.
|
||||
*
|
||||
* @param {string} clientId
|
||||
* @param {Pick<import("@actions/core"), "getIDToken">} core
|
||||
* @param {import("@octokit/request").request} request
|
||||
*/
|
||||
export async function createOidcAuth(clientId, core, request) {
|
||||
const audience = `${process.env.GITHUB_SERVER_URL || "https://github.com"}/login/oauth`;
|
||||
const token = await core.getIDToken(audience);
|
||||
|
||||
/**
|
||||
* @param {{ installationId: number, repositoryNames?: string[], permissions?: Record<string, string> }} options
|
||||
*/
|
||||
const auth = async ({ installationId, repositoryNames, permissions }) => {
|
||||
const { data } = await request(
|
||||
"POST /app/installations/{installation_id}/access_tokens{?client_id}",
|
||||
{
|
||||
installation_id: installationId,
|
||||
client_id: clientId,
|
||||
repositories: repositoryNames,
|
||||
permissions,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
},
|
||||
);
|
||||
|
||||
return { token: data.token, expiresAt: data.expires_at };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import("@octokit/request").request} hookRequest
|
||||
* @param {string} route
|
||||
* @param {Record<string, unknown>} [parameters]
|
||||
*/
|
||||
auth.hook = (hookRequest, route, parameters) => {
|
||||
const endpoint = hookRequest.endpoint(route, parameters);
|
||||
const url = new URL(endpoint.url);
|
||||
url.searchParams.set("client_id", clientId);
|
||||
endpoint.url = url.toString();
|
||||
endpoint.headers.authorization = `Bearer ${token}`;
|
||||
return hookRequest(endpoint);
|
||||
};
|
||||
|
||||
return auth;
|
||||
}
|
||||
+13
-5
@@ -1,5 +1,6 @@
|
||||
import pRetry from "p-retry";
|
||||
import isNetworkError from "is-network-error";
|
||||
import { createOidcAuth } from "./create-oidc-auth.js";
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
@@ -31,13 +32,20 @@ export async function main(
|
||||
throw new Error("Cannot use 'enterprise' input with 'owner' or 'repositories' inputs");
|
||||
}
|
||||
|
||||
// The enterprise installation lookup endpoint doesn't accept OIDC tokens
|
||||
if (enterprise && !privateKey) {
|
||||
throw new Error("The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.");
|
||||
}
|
||||
|
||||
const target = resolveInstallationTarget(enterprise, owner, repositories, core);
|
||||
|
||||
const auth = createAppAuth({
|
||||
appId: clientId,
|
||||
privateKey,
|
||||
request,
|
||||
});
|
||||
if (!privateKey) {
|
||||
core.info("No 'private-key' provided; authenticating with GitHub Actions OIDC.");
|
||||
}
|
||||
|
||||
const auth = privateKey
|
||||
? createAppAuth({ appId: clientId, privateKey, request })
|
||||
: await createOidcAuth(clientId, core, request);
|
||||
|
||||
const { authentication, installationId, appSlug } = await pRetry(
|
||||
() => getTokenFromTarget(request, auth, target, permissions),
|
||||
|
||||
@@ -24,7 +24,12 @@ async function run() {
|
||||
}
|
||||
const privateKey = core.getInput("private-key");
|
||||
if (!privateKey) {
|
||||
throw new Error("The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.");
|
||||
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_URL || !process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) {
|
||||
throw new Error("The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.");
|
||||
}
|
||||
if (!core.getInput("client-id")) {
|
||||
throw new Error("The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.");
|
||||
}
|
||||
}
|
||||
const enterprise = core.getInput("enterprise");
|
||||
const owner = core.getInput("owner");
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "create-github-app-token",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0-beta",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "create-github-app-token",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0-beta",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^3.0.1",
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "create-github-app-token",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0-beta",
|
||||
"description": "GitHub Action for creating a GitHub App Installation Access Token",
|
||||
"engines": {
|
||||
"node": ">=24.4.0"
|
||||
|
||||
@@ -34,3 +34,4 @@ We have tests both for the `main.js` and `post.js` scripts.
|
||||
|
||||
- If you do not expect an error, take [main-token-permissions-set.test.js](main-token-permissions-set.test.js) as a starting point.
|
||||
- If your test has an expected error, take [main-missing-client-and-app-id.test.js](main-missing-client-and-app-id.test.js) as a starting point.
|
||||
- To authenticate with GitHub Actions OIDC instead of a private key, pass `OIDC_ENV` to `test()`, as in [main-oidc-token-permissions-set.test.js](main-oidc-token-permissions-set.test.js).
|
||||
+62
-2
@@ -148,17 +148,77 @@ GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
|
||||
`;
|
||||
|
||||
exports[`main-missing-private-key.test.js > stderr 1`] = `
|
||||
The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.
|
||||
The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.
|
||||
`;
|
||||
|
||||
exports[`main-missing-private-key.test.js > stdout 1`] = `
|
||||
::error::The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.
|
||||
::error::The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.
|
||||
`;
|
||||
|
||||
exports[`main-missing-repository.test.js > stderr 1`] = `
|
||||
GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'
|
||||
`;
|
||||
|
||||
exports[`main-oidc-custom-server-url.test.js > stdout 1`] = `
|
||||
Input 'repositories' is not set. Creating token for all repositories owned by actions.
|
||||
No 'private-key' provided; authenticating with GitHub Actions OIDC.
|
||||
::debug::ID token url is http://127.0.0.1:<port>/token?api-version=2.0&audience=https%253A%252F%252Fgithub.example.com%252Flogin%252Foauth
|
||||
::add-mask::oidc-token
|
||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=installation-id::123456
|
||||
|
||||
::set-output name=app-slug::github-actions
|
||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
::save-state name=expiresAt::2016-07-11T22:14:10Z
|
||||
--- OIDC REQUESTS ---
|
||||
GET /token?api-version=2.0&audience=https%3A%2F%2Fgithub.example.com%2Flogin%2Foauth
|
||||
--- REQUESTS ---
|
||||
GET /users/actions/installation?client_id=Iv1.0123456789abcdef
|
||||
POST /app/installations/123456/access_tokens?client_id=Iv1.0123456789abcdef
|
||||
null
|
||||
`;
|
||||
|
||||
exports[`main-oidc-enterprise-requires-private-key.test.js > stderr 1`] = `
|
||||
The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-enterprise-requires-private-key.test.js > stdout 1`] = `
|
||||
::error::The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-missing-client-id.test.js > stderr 1`] = `
|
||||
The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-missing-client-id.test.js > stdout 1`] = `
|
||||
::error::The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-token-permissions-set.test.js > stdout 1`] = `
|
||||
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
|
||||
No 'private-key' provided; authenticating with GitHub Actions OIDC.
|
||||
::debug::ID token url is http://127.0.0.1:<port>/token?api-version=2.0&audience=https%253A%252F%252Fgithub.com%252Flogin%252Foauth
|
||||
::add-mask::oidc-token
|
||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=installation-id::123456
|
||||
|
||||
::set-output name=app-slug::github-actions
|
||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
::save-state name=expiresAt::2016-07-11T22:14:10Z
|
||||
--- OIDC REQUESTS ---
|
||||
GET /token?api-version=2.0&audience=https%3A%2F%2Fgithub.com%2Flogin%2Foauth
|
||||
--- REQUESTS ---
|
||||
GET /repos/actions/create-github-app-token/installation?client_id=Iv1.0123456789abcdef
|
||||
POST /app/installations/123456/access_tokens?client_id=Iv1.0123456789abcdef
|
||||
{"repositories":["create-github-app-token"],"permissions":{"issues":"write"}}
|
||||
`;
|
||||
|
||||
exports[`main-private-key-with-escaped-newlines.test.js > stdout 1`] = `
|
||||
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
|
||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
@@ -13,7 +13,10 @@ for (const [key, value] of Object.entries({
|
||||
const _error = console.error;
|
||||
console.error = (err) => _error(err?.message ?? err);
|
||||
|
||||
// Verify `main` exits with an error when `private-key` is not set.
|
||||
delete process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
|
||||
delete process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
||||
|
||||
// Verify a missing private-key without OIDC permissions produces an actionable error.
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
process.exitCode = 0;
|
||||
@@ -0,0 +1,24 @@
|
||||
import { OIDC_ENV, test } from "./main.js";
|
||||
|
||||
// Verify the OIDC audience is derived from `GITHUB_SERVER_URL`, using an `owner` target.
|
||||
await test((mockPool) => {
|
||||
process.env.GITHUB_SERVER_URL = "https://github.example.com";
|
||||
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||
delete process.env.INPUT_REPOSITORIES;
|
||||
|
||||
mockPool
|
||||
.intercept({
|
||||
path: `/users/${process.env.INPUT_OWNER}/installation?client_id=${OIDC_ENV["INPUT_CLIENT-ID"]}`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
"user-agent": "actions/create-github-app-token",
|
||||
authorization: "Bearer oidc-token",
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
200,
|
||||
{ id: "123456", app_slug: "github-actions" },
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}, OIDC_ENV);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { OIDC_ENV } from "./main.js";
|
||||
|
||||
for (const [key, value] of Object.entries({
|
||||
...OIDC_ENV,
|
||||
ACTIONS_ID_TOKEN_REQUEST_URL: "https://oidc.example/token",
|
||||
INPUT_ENTERPRISE: "test-enterprise",
|
||||
})) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
|
||||
const _error = console.error;
|
||||
console.error = (err) => _error(err?.message ?? err);
|
||||
|
||||
// Verify `main` exits with an error when OIDC authentication is used with the `enterprise` input.
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
process.exitCode = 0;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { OIDC_ENV } from "./main.js";
|
||||
|
||||
for (const [key, value] of Object.entries({
|
||||
...OIDC_ENV,
|
||||
"INPUT_CLIENT-ID": "",
|
||||
"INPUT_APP-ID": "123456",
|
||||
ACTIONS_ID_TOKEN_REQUEST_URL: "https://oidc.example/token",
|
||||
})) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
|
||||
const _error = console.error;
|
||||
console.error = (err) => _error(err?.message ?? err);
|
||||
|
||||
// Verify the deprecated `app-id` input is rejected for OIDC authentication.
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
process.exitCode = 0;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { OIDC_ENV, test } from "./main.js";
|
||||
|
||||
// Verify `main` authenticates with an OIDC token when `private-key` isn’t set, and that the
|
||||
// OIDC audience falls back to https://github.com when `GITHUB_SERVER_URL` isn’t set.
|
||||
await test(() => {
|
||||
delete process.env.GITHUB_SERVER_URL;
|
||||
process.env["INPUT_PERMISSION-ISSUES"] = "write";
|
||||
}, OIDC_ENV);
|
||||
+61
-5
@@ -1,5 +1,7 @@
|
||||
// Base for all `main` tests.
|
||||
// @ts-check
|
||||
import { createServer } from "node:http";
|
||||
|
||||
import { createMockAgent } from "./mock-agent.js";
|
||||
|
||||
export const DEFAULT_ENV = {
|
||||
@@ -42,6 +44,48 @@ x3WQZRiXlWejSMUAHuMwXrhGlltF3lw83+xAjnqsVp75kGS6OH61
|
||||
"INPUT_PERMISSION-ADMINISTRATION": "",
|
||||
};
|
||||
|
||||
// Authenticate with GitHub Actions OIDC instead of a private key.
|
||||
export const OIDC_ENV = {
|
||||
...DEFAULT_ENV,
|
||||
"INPUT_PRIVATE-KEY": "",
|
||||
ACTIONS_ID_TOKEN_REQUEST_TOKEN: "runner-token",
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts a local server that mimics the Actions OIDC token endpoint, because
|
||||
* `core.getIDToken()` uses `@actions/http-client`, which `MockAgent` can't intercept.
|
||||
*/
|
||||
async function startOidcServer() {
|
||||
/** @type {string[]} */
|
||||
const requests = [];
|
||||
const server = createServer((request, response) => {
|
||||
requests.push(`${request.method} ${request.url}`);
|
||||
const authorized = request.headers.authorization === "Bearer runner-token";
|
||||
response.writeHead(authorized ? 200 : 401, {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
response.end(JSON.stringify(authorized ? { value: "oidc-token" } : { message: "Unauthorized" }));
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(undefined)));
|
||||
const { port } = /** @type {import("node:net").AddressInfo} */ (server.address());
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = `http://127.0.0.1:${port}/token?api-version=2.0`;
|
||||
|
||||
// `core.getIDToken()` logs the token URL, so replace the random port to keep snapshots stable.
|
||||
const write = process.stdout.write.bind(process.stdout);
|
||||
process.stdout.write = /** @type {any} */ (
|
||||
(/** @type {unknown} */ chunk, /** @type {any[]} */ ...args) =>
|
||||
write(
|
||||
typeof chunk === "string" ? chunk.replaceAll(`127.0.0.1:${port}`, "127.0.0.1:<port>") : chunk,
|
||||
...args
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
requests,
|
||||
close: () => new Promise((resolve) => server.close(() => resolve(undefined))),
|
||||
};
|
||||
}
|
||||
|
||||
export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
process.env[key] = value;
|
||||
@@ -55,6 +99,12 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
|
||||
// Calling `auth({ type: "app" })` to obtain a JWT doesn’t make network requests, so no need to intercept.
|
||||
|
||||
// Without a private key, the action authenticates with an OIDC token and passes `client_id`.
|
||||
const oidcServer = env["INPUT_PRIVATE-KEY"] ? undefined : await startOidcServer();
|
||||
const clientIdQuery = oidcServer ? `?client_id=${env["INPUT_CLIENT-ID"]}` : "";
|
||||
// JWT creation is not idempotent, so the `authorization` header is only asserted for OIDC.
|
||||
const authorization = oidcServer ? { authorization: "Bearer oidc-token" } : {};
|
||||
|
||||
// Mock installation ID and app slug request
|
||||
const mockInstallationId = "123456";
|
||||
const mockAppSlug = "github-actions";
|
||||
@@ -71,12 +121,12 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
|
||||
mockPool
|
||||
.intercept({
|
||||
path: `${basePath}/repos/${owner}/${repo}/installation`,
|
||||
path: `${basePath}/repos/${owner}/${repo}/installation${clientIdQuery}`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
"user-agent": "actions/create-github-app-token",
|
||||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
||||
...authorization,
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
@@ -92,12 +142,12 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
|
||||
mockPool
|
||||
.intercept({
|
||||
path: `${basePath}/app/installations/${mockInstallationId}/access_tokens`,
|
||||
path: `${basePath}/app/installations/${mockInstallationId}/access_tokens${clientIdQuery}`,
|
||||
method: "POST",
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
"user-agent": "actions/create-github-app-token",
|
||||
// Note: Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
||||
...authorization,
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
@@ -113,12 +163,18 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
|
||||
if (oidcServer) {
|
||||
await oidcServer.close();
|
||||
console.log("--- OIDC REQUESTS ---");
|
||||
console.log(oidcServer.requests.join("\n"));
|
||||
}
|
||||
|
||||
console.log("--- REQUESTS ---");
|
||||
const calls = mockAgent
|
||||
.getCallHistory()
|
||||
.calls()
|
||||
.map((call) => {
|
||||
const route = `${call.method} ${call.path}`;
|
||||
const route = `${call.method} ${call.path}${new URL(call.fullUrl).search}`;
|
||||
if (call.method === "GET") return route;
|
||||
|
||||
return `${route}\n${call.body}`;
|
||||
|
||||
Reference in new issue
Block a user