
There have been a number of GitHub issues recently due to users not adding actions/checkout before calling "auth", which makes the credentials unavailable to future steps. Worse, some people are putting checkout _after_ auth, which overwrites the generated credentials with a checkout of the repo. This adds a feature that emits a warning with the workspace is empty.
82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
'use strict';
|
|
|
|
import 'mocha';
|
|
import { expect } from 'chai';
|
|
|
|
import { tmpdir } from 'os';
|
|
|
|
import { buildDomainWideDelegationJWT, isEmptyDir } from '../src/utils';
|
|
|
|
describe('Utils', () => {
|
|
describe('#buildDomainWideDelegationJWT', () => {
|
|
const cases = [
|
|
{
|
|
name: 'default',
|
|
serviceAccount: 'my-service@example.com',
|
|
lifetime: 1000,
|
|
},
|
|
{
|
|
name: 'with subject',
|
|
serviceAccount: 'my-service@example.com',
|
|
subject: 'my-subject',
|
|
lifetime: 1000,
|
|
},
|
|
{
|
|
name: 'with scopes',
|
|
serviceAccount: 'my-service@example.com',
|
|
scopes: ['scope1', 'scope2'],
|
|
lifetime: 1000,
|
|
},
|
|
];
|
|
|
|
cases.forEach((tc) => {
|
|
it(tc.name, async () => {
|
|
const val = buildDomainWideDelegationJWT(
|
|
tc.serviceAccount,
|
|
tc.subject,
|
|
tc.scopes,
|
|
tc.lifetime,
|
|
);
|
|
|
|
const body = JSON.parse(val);
|
|
expect(body.iss).to.eq(tc.serviceAccount);
|
|
expect(body.aud).to.eq('https://oauth2.googleapis.com/token');
|
|
|
|
if (tc.subject) {
|
|
expect(body.sub).to.eq(tc.subject);
|
|
} else {
|
|
expect(body.sub).to.not.be;
|
|
}
|
|
|
|
if (tc.scopes) {
|
|
expect(body.scope).to.eq(tc.scopes.join(' '));
|
|
} else {
|
|
expect(body.scope).to.not.be;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#isEmptyDir', async () => {
|
|
const cases = [
|
|
{
|
|
name: 'non-existent dir',
|
|
dir: '/this/path/definitely/does/not/exist',
|
|
exp: true,
|
|
},
|
|
{
|
|
name: 'exists',
|
|
dir: tmpdir(),
|
|
exp: false,
|
|
},
|
|
];
|
|
|
|
cases.forEach((tc) => {
|
|
it(tc.name, async () => {
|
|
const isEmpty = await isEmptyDir(tc.dir);
|
|
expect(isEmpty).to.eq(tc.exp);
|
|
});
|
|
});
|
|
});
|
|
});
|