Drop chai and mocha deps (#342)

This commit is contained in:
Seth Vargo 2023-11-15 08:33:15 -05:00 committed by GitHub
parent 43a59886fc
commit 04900d1e97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 302 additions and 720 deletions

View File

@ -1,3 +1,17 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: 2
updates:
- package-ecosystem: 'npm'

View File

@ -1,3 +1,17 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'Draft release'
on:

View File

@ -1,3 +1,17 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'Release'
on:

View File

@ -1,3 +1,17 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'Test'
on:

View File

@ -1,3 +1,17 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'Troubleshooting'
on:

4
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

6
dist/post/index.js vendored

File diff suppressed because one or more lines are too long

711
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
"build": "ncc build -m src/main.ts -o dist/main && ncc build -m src/post.ts -o dist/post",
"lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write **/*.ts",
"test": "mocha -r ts-node/register -t 120s 'tests/**/*.test.ts'"
"test": " node --require ts-node/register --test **/*.test.ts **/**/*.test.ts"
},
"repository": {
"type": "git",
@ -28,18 +28,14 @@
"@google-github-actions/actions-utils": "^0.4.9"
},
"devDependencies": {
"@types/chai": "^4.3.10",
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@vercel/ncc": "^0.38.1",
"chai": "^4.3.10",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"mocha": "^10.2.0",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { HttpClient } from '@actions/http-client';
import { URLSearchParams } from 'url';

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* Defines the main interface for all clients that generate credentials.

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { createSign } from 'crypto';
import {

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { URL } from 'url';
import { writeSecureFile } from '@google-github-actions/actions-utils';
@ -192,9 +204,7 @@ export class WorkloadIdentityClient extends BaseClient implements AuthClient {
audience: `//iam.googleapis.com/${this.#providerID}`,
subject_token_type: 'urn:ietf:params:oauth:token-type:jwt',
token_url: 'https://sts.googleapis.com/v1/token',
service_account_impersonation_url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${
this.#serviceAccount
}:generateAccessToken`,
service_account_impersonation_url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${this.#serviceAccount}:generateAccessToken`,
credential_source: {
url: requestURL,
headers: {

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { join as pathjoin } from 'path';

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { getBooleanInput, setFailed, info as logInfo } from '@actions/core';
import { errorMessage, forceRemove } from '@google-github-actions/actions-utils';

View File

@ -1,4 +1,16 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { randomFilename } from '@google-github-actions/actions-utils';

View File

@ -1,7 +1,19 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'mocha';
import { expect } from 'chai';
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { join as pathjoin } from 'path';
import { readFileSync } from 'fs';
@ -31,23 +43,19 @@ const credentialsJSON = `
describe('CredentialsJSONClient', () => {
describe('#parseServiceAccountKeyJSON', () => {
it('throws exception on invalid json', async () => {
const fn = (): CredentialsJSONClient => {
return new CredentialsJSONClient({
assert.rejects(async () => {
new CredentialsJSONClient({
credentialsJSON: 'invalid json',
});
};
expect(fn).to.throw(SyntaxError);
}, SyntaxError);
});
it('handles base64', async () => {
const fn = (): CredentialsJSONClient => {
return new CredentialsJSONClient({
credentialsJSON: Buffer.from('{}').toString('base64'),
assert.rejects(async () => {
new CredentialsJSONClient({
credentialsJSON: 'base64',
});
};
expect(fn).to.not.throw(SyntaxError);
}, SyntaxError);
});
});
@ -58,7 +66,7 @@ describe('CredentialsJSONClient', () => {
});
const token = await client.getAuthToken();
expect(token).to.be;
assert.ok(token);
});
});
@ -69,7 +77,7 @@ describe('CredentialsJSONClient', () => {
});
const token = await client.signJWT('thisismy.jwt');
expect(token).to.be;
assert.ok(token);
});
});
@ -80,7 +88,7 @@ describe('CredentialsJSONClient', () => {
});
const result = await client.getProjectID();
expect(result).to.eq('my-project');
assert.deepStrictEqual(result, 'my-project');
});
it('prefers the override if given', async () => {
@ -90,7 +98,7 @@ describe('CredentialsJSONClient', () => {
});
const result = await client.getProjectID();
expect(result).to.eq('my-other-project');
assert.deepStrictEqual(result, 'my-other-project');
});
});
@ -101,7 +109,7 @@ describe('CredentialsJSONClient', () => {
});
const result = await client.getServiceAccount();
expect(result).to.eq('my-service-account@my-project.iam.gserviceaccount.com');
assert.deepStrictEqual(result, 'my-service-account@my-project.iam.gserviceaccount.com');
});
});
@ -118,7 +126,7 @@ describe('CredentialsJSONClient', () => {
const data = readFileSync(pth);
const got = JSON.parse(data.toString('utf8'));
expect(got).to.deep.equal(exp);
assert.deepStrictEqual(got, exp);
});
});
});

View File

@ -1,7 +1,19 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'mocha';
import { expect } from 'chai';
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { tmpdir } from 'os';
import { join as pathjoin } from 'path';
@ -24,7 +36,7 @@ describe('WorkloadIdentityClient', () => {
});
const result = await client.getProjectID();
expect(result).to.eq('my-project');
assert.deepStrictEqual(result, 'my-project');
});
it('prefers the override if given', async () => {
@ -39,11 +51,11 @@ describe('WorkloadIdentityClient', () => {
});
const result = await client.getProjectID();
expect(result).to.eq('my-other-project');
assert.deepStrictEqual(result, 'my-other-project');
});
it('throws an error when extraction fails', async () => {
const fn = () => {
assert.rejects(async () => {
return new WorkloadIdentityClient({
providerID: 'my-provider',
token: 'my-token',
@ -52,8 +64,7 @@ describe('WorkloadIdentityClient', () => {
oidcTokenRequestURL: 'https://example.com/',
oidcTokenRequestToken: 'token',
});
};
return expect(fn).to.throw(Error);
}, Error);
});
});
@ -69,7 +80,7 @@ describe('WorkloadIdentityClient', () => {
oidcTokenRequestToken: 'token',
});
const result = await client.getServiceAccount();
expect(result).to.eq('my-service@my-project.iam.gserviceaccount.com');
assert.deepStrictEqual(result, 'my-service@my-project.iam.gserviceaccount.com');
});
});
@ -109,7 +120,7 @@ describe('WorkloadIdentityClient', () => {
const data = readFileSync(pth);
const got = JSON.parse(data.toString('utf8'));
expect(got).to.deep.equal(exp);
assert.deepStrictEqual(got, exp);
});
});
});

View File

@ -1,7 +1,19 @@
'use strict';
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'mocha';
import { expect } from 'chai';
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { buildDomainWideDelegationJWT, generateCredentialsFilename } from '../src/utils';
@ -37,20 +49,10 @@ describe('Utils', () => {
);
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;
}
assert.deepStrictEqual(body.iss, tc.serviceAccount);
assert.deepStrictEqual(body.aud, 'https://oauth2.googleapis.com/token');
assert.deepStrictEqual(body.sub, tc.subject);
assert.deepStrictEqual(body.scope, tc.scopes?.join(' '));
});
});
});
@ -59,7 +61,7 @@ describe('Utils', () => {
it('returns a string matching the regex', () => {
for (let i = 0; i < 10; i++) {
const filename = generateCredentialsFilename();
expect(filename).to.match(/gha-creds-[0-9a-z]{16}\.json/);
assert.match(filename, /gha-creds-[0-9a-z]{16}\.json/);
}
});
});