mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-26 22:26:08 +08:00
test: githubActionsRuntimeToken
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
85ef93202e
commit
039779492c
1
__tests__/fixtures/runtimeToken.txt
Normal file
1
__tests__/fixtures/runtimeToken.txt
Normal file
@ -0,0 +1 @@
|
||||
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImVCWl9jbjNzWFlBZDBjaDRUSEJLSElnT3dPRSJ9.eyJuYW1laWQiOiJkZGRkZGRkZC1kZGRkLWRkZGQtZGRkZC1kZGRkZGRkZGRkZGQiLCJzY3AiOiJBY3Rpb25zLkdlbmVyaWNSZWFkOjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCBBY3Rpb25zLlVwbG9hZEFydGlmYWN0czowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAvMTpCdWlsZC9CdWlsZC85MDIgTG9jYXRpb25TZXJ2aWNlLkNvbm5lY3QgUmVhZEFuZFVwZGF0ZUJ1aWxkQnlVcmk6MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwLzE6QnVpbGQvQnVpbGQvOTAyIiwiSWRlbnRpdHlUeXBlQ2xhaW0iOiJTeXN0ZW06U2VydmljZUlkZW50aXR5IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvc2lkIjoiREREREREREQtRERERC1ERERELUREREQtREREREREREREREREIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9wcmltYXJ5c2lkIjoiZGRkZGRkZGQtZGRkZC1kZGRkLWRkZGQtZGRkZGRkZGRkZGRkIiwiYXVpIjoiN2U0MGNlZWQtNWQxMi00OTRkLWI2M2QtOGVhMGQ2ZGRhMzRkIiwic2lkIjoiMmFlM2JkOTgtN2Q4NC00MGQxLWE1YjEtMWM5NTY1MmY5OTRjIiwiYWMiOiJbe1wiU2NvcGVcIjpcInJlZnMvaGVhZHMvbWFzdGVyXCIsXCJQZXJtaXNzaW9uXCI6M31dIiwiYWNzbCI6IjEwIiwib3JjaGlkIjoiNmViYTgwMjktZDliNy00ZGJkLWJkNzItM2I3ODFhZjYxNzkwLmJ1aWxkLl9fZGVmYXVsdCIsImlzcyI6InZzdG9rZW4uYWN0aW9ucy5naXRodWJ1c2VyY29udGVudC5jb20iLCJhdWQiOiJ2c3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tfHZzbzo1YWQwMGYyMy05ZmEwLTRiZGEtYjQyNi1mMWIyNzg5MWM5MTkiLCJuYmYiOjE2NzUwNDE1NjcsImV4cCI6MTY3NTA2NDM2N30.lWJuHGC7wQ9pgHXs4dMMSsflUUi6zasOzH8rz4EFvZfIlzyMcP1sZQeySNGAZ9z91JkpREzRPHFOCTp0hM9MbN6jcA05zvhSXiEE5cZikm_z32g0c5um3F3LneHwOWZeM_Lw29FBMnswuCaljvCi9p50M4wRbtqJpoYfIwvm5-nLcBbSrQZcMfPEfVXHSBCUqdoiVAunXsUrnCsKURL5T_UJIBUYBGLUrZqf2m8YnO7Wg_Q11wSz33W0gDR4_PdnOiJY1hL0vAOiRbNG0RLPA0A2QCmvlwdJOWJKOS4GgWoRr-3_PQYNy5We70CpZTpVvHtx5PQ9l65qTASNmVeg4Q
|
@ -1,4 +1,6 @@
|
||||
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import {GitHub, GitHubRepo} from '../src/github';
|
||||
|
||||
@ -45,6 +47,31 @@ describe('serverURL', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('actionsRuntimeToken', () => {
|
||||
const originalEnv = process.env;
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
process.env = {
|
||||
...originalEnv
|
||||
};
|
||||
});
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
it('empty', async () => {
|
||||
process.env.ACTIONS_RUNTIME_TOKEN = '';
|
||||
const github = new GitHub();
|
||||
expect(github.actionsRuntimeToken).toEqual({});
|
||||
});
|
||||
it('fixture', async () => {
|
||||
process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(__dirname, 'fixtures', 'runtimeToken.txt')).toString().trim();
|
||||
const github = new GitHub();
|
||||
const runtimeToken = github.actionsRuntimeToken;
|
||||
expect(runtimeToken.ac).toEqual('[{"Scope":"refs/heads/master","Permission":3}]');
|
||||
expect(runtimeToken.iss).toEqual('vstoken.actions.githubusercontent.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('repoData', () => {
|
||||
it('returns GitHub repository', async () => {
|
||||
const github = new GitHub();
|
||||
|
@ -6,7 +6,7 @@ import {Context} from '@actions/github/lib/context';
|
||||
|
||||
export type GitHubRepo = OctoOpenApiTypes['schemas']['repository'];
|
||||
|
||||
export interface GitHubRuntimeToken extends JwtPayload {
|
||||
export interface GitHubActionsRuntimeToken extends JwtPayload {
|
||||
ac?: string;
|
||||
}
|
||||
|
||||
@ -30,8 +30,9 @@ export class GitHub {
|
||||
return process.env.GITHUB_SERVER_URL || 'https://github.com';
|
||||
}
|
||||
|
||||
get runtimeToken(): GitHubRuntimeToken {
|
||||
return jwt_decode<GitHubRuntimeToken>(`${process.env['ACTIONS_RUNTIME_TOKEN']}`);
|
||||
get actionsRuntimeToken(): GitHubActionsRuntimeToken {
|
||||
const token = process.env['ACTIONS_RUNTIME_TOKEN'] || '';
|
||||
return token ? jwt_decode<GitHubActionsRuntimeToken>(token) : {};
|
||||
}
|
||||
|
||||
public repoData(): Promise<GitHubRepo> {
|
||||
|
Loading…
Reference in New Issue
Block a user