mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 11:36:10 +08:00
Merge pull request #50 from crazy-max/github-throw-runtime-token
github: throw if runtime token invalid
This commit is contained in:
commit
d153cfaf3c
@ -130,18 +130,12 @@ describe('printActionsRuntimeTokenACs', () => {
|
|||||||
process.env = originalEnv;
|
process.env = originalEnv;
|
||||||
});
|
});
|
||||||
it('empty', async () => {
|
it('empty', async () => {
|
||||||
const warnSpy = jest.spyOn(core, 'warning');
|
|
||||||
process.env.ACTIONS_RUNTIME_TOKEN = '';
|
process.env.ACTIONS_RUNTIME_TOKEN = '';
|
||||||
await GitHub.printActionsRuntimeTokenACs();
|
await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrowError(new Error('ACTIONS_RUNTIME_TOKEN not set'));
|
||||||
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
||||||
expect(warnSpy).toHaveBeenCalledWith(`ACTIONS_RUNTIME_TOKEN not set`);
|
|
||||||
});
|
});
|
||||||
it('malformed', async () => {
|
it('malformed', async () => {
|
||||||
const warnSpy = jest.spyOn(core, 'warning');
|
|
||||||
process.env.ACTIONS_RUNTIME_TOKEN = 'foo';
|
process.env.ACTIONS_RUNTIME_TOKEN = 'foo';
|
||||||
await GitHub.printActionsRuntimeTokenACs();
|
await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrowError(new Error("Cannot parse GitHub Actions Runtime Token: Invalid token specified: Cannot read properties of undefined (reading 'replace')"));
|
||||||
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
||||||
expect(warnSpy).toHaveBeenCalledWith(`Cannot parse Actions Runtime Token: Invalid token specified: Cannot read properties of undefined (reading 'replace')`);
|
|
||||||
});
|
});
|
||||||
it('refs/heads/master', async () => {
|
it('refs/heads/master', async () => {
|
||||||
const infoSpy = jest.spyOn(core, 'info');
|
const infoSpy = jest.spyOn(core, 'info');
|
||||||
|
@ -59,12 +59,10 @@ export class GitHub {
|
|||||||
try {
|
try {
|
||||||
jwt = GitHub.actionsRuntimeToken;
|
jwt = GitHub.actionsRuntimeToken;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.warning(`Cannot parse Actions Runtime Token: ${e.message}`);
|
throw new Error(`Cannot parse GitHub Actions Runtime Token: ${e.message}`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!jwt) {
|
if (!jwt) {
|
||||||
core.warning(`ACTIONS_RUNTIME_TOKEN not set`);
|
throw new Error(`ACTIONS_RUNTIME_TOKEN not set`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
<Array<GitHubActionsRuntimeTokenAC>>JSON.parse(`${jwt.ac}`).forEach(ac => {
|
<Array<GitHubActionsRuntimeTokenAC>>JSON.parse(`${jwt.ac}`).forEach(ac => {
|
||||||
@ -85,7 +83,7 @@ export class GitHub {
|
|||||||
core.info(`${ac.Scope}: ${permission}`);
|
core.info(`${ac.Scope}: ${permission}`);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.warning(`Cannot parse Actions Runtime Token Access Controls: ${e.message}`);
|
throw new Error(`Cannot parse GitHub Actions Runtime Token ACs: ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user