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 version: 2
updates: updates:
- package-ecosystem: 'npm' - 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' name: 'Draft release'
on: 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' name: 'Release'
on: 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' name: 'Test'
on: 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' name: 'Troubleshooting'
on: 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", "build": "ncc build -m src/main.ts -o dist/main && ncc build -m src/post.ts -o dist/post",
"lint": "eslint . --ext .ts,.tsx", "lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write **/*.ts", "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": { "repository": {
"type": "git", "type": "git",
@ -28,18 +28,14 @@
"@google-github-actions/actions-utils": "^0.4.9" "@google-github-actions/actions-utils": "^0.4.9"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.3.10",
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0", "@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "^6.10.0", "@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.10.0", "@typescript-eslint/parser": "^6.11.0",
"@vercel/ncc": "^0.38.1", "@vercel/ncc": "^0.38.1",
"chai": "^4.3.10",
"eslint": "^8.53.0", "eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0", "eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1", "eslint-plugin-prettier": "^5.0.1",
"mocha": "^10.2.0", "prettier": "^3.1.0",
"prettier": "^3.0.3",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^5.2.2" "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 { HttpClient } from '@actions/http-client';
import { URLSearchParams } from 'url'; 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. * 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 { createSign } from 'crypto';
import { 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 { URL } from 'url';
import { writeSecureFile } from '@google-github-actions/actions-utils'; 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}`, audience: `//iam.googleapis.com/${this.#providerID}`,
subject_token_type: 'urn:ietf:params:oauth:token-type:jwt', subject_token_type: 'urn:ietf:params:oauth:token-type:jwt',
token_url: 'https://sts.googleapis.com/v1/token', token_url: 'https://sts.googleapis.com/v1/token',
service_account_impersonation_url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${ service_account_impersonation_url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${this.#serviceAccount}:generateAccessToken`,
this.#serviceAccount
}:generateAccessToken`,
credential_source: { credential_source: {
url: requestURL, url: requestURL,
headers: { 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'; 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 { getBooleanInput, setFailed, info as logInfo } from '@actions/core';
import { errorMessage, forceRemove } from '@google-github-actions/actions-utils'; 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'; 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 { describe, it } from 'node:test';
import { expect } from 'chai'; import assert from 'node:assert';
import { join as pathjoin } from 'path'; import { join as pathjoin } from 'path';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
@ -31,23 +43,19 @@ const credentialsJSON = `
describe('CredentialsJSONClient', () => { describe('CredentialsJSONClient', () => {
describe('#parseServiceAccountKeyJSON', () => { describe('#parseServiceAccountKeyJSON', () => {
it('throws exception on invalid json', async () => { it('throws exception on invalid json', async () => {
const fn = (): CredentialsJSONClient => { assert.rejects(async () => {
return new CredentialsJSONClient({ new CredentialsJSONClient({
credentialsJSON: 'invalid json', credentialsJSON: 'invalid json',
}); });
}; }, SyntaxError);
expect(fn).to.throw(SyntaxError);
}); });
it('handles base64', async () => { it('handles base64', async () => {
const fn = (): CredentialsJSONClient => { assert.rejects(async () => {
return new CredentialsJSONClient({ new CredentialsJSONClient({
credentialsJSON: Buffer.from('{}').toString('base64'), credentialsJSON: 'base64',
}); });
}; }, SyntaxError);
expect(fn).to.not.throw(SyntaxError);
}); });
}); });
@ -58,7 +66,7 @@ describe('CredentialsJSONClient', () => {
}); });
const token = await client.getAuthToken(); 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'); 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(); const result = await client.getProjectID();
expect(result).to.eq('my-project'); assert.deepStrictEqual(result, 'my-project');
}); });
it('prefers the override if given', async () => { it('prefers the override if given', async () => {
@ -90,7 +98,7 @@ describe('CredentialsJSONClient', () => {
}); });
const result = await client.getProjectID(); 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(); 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 data = readFileSync(pth);
const got = JSON.parse(data.toString('utf8')); 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 { describe, it } from 'node:test';
import { expect } from 'chai'; import assert from 'node:assert';
import { tmpdir } from 'os'; import { tmpdir } from 'os';
import { join as pathjoin } from 'path'; import { join as pathjoin } from 'path';
@ -24,7 +36,7 @@ describe('WorkloadIdentityClient', () => {
}); });
const result = await client.getProjectID(); const result = await client.getProjectID();
expect(result).to.eq('my-project'); assert.deepStrictEqual(result, 'my-project');
}); });
it('prefers the override if given', async () => { it('prefers the override if given', async () => {
@ -39,11 +51,11 @@ describe('WorkloadIdentityClient', () => {
}); });
const result = await client.getProjectID(); 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 () => { it('throws an error when extraction fails', async () => {
const fn = () => { assert.rejects(async () => {
return new WorkloadIdentityClient({ return new WorkloadIdentityClient({
providerID: 'my-provider', providerID: 'my-provider',
token: 'my-token', token: 'my-token',
@ -52,8 +64,7 @@ describe('WorkloadIdentityClient', () => {
oidcTokenRequestURL: 'https://example.com/', oidcTokenRequestURL: 'https://example.com/',
oidcTokenRequestToken: 'token', oidcTokenRequestToken: 'token',
}); });
}; }, Error);
return expect(fn).to.throw(Error);
}); });
}); });
@ -69,7 +80,7 @@ describe('WorkloadIdentityClient', () => {
oidcTokenRequestToken: 'token', oidcTokenRequestToken: 'token',
}); });
const result = await client.getServiceAccount(); 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 data = readFileSync(pth);
const got = JSON.parse(data.toString('utf8')); 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 { describe, it } from 'node:test';
import { expect } from 'chai'; import assert from 'node:assert';
import { buildDomainWideDelegationJWT, generateCredentialsFilename } from '../src/utils'; import { buildDomainWideDelegationJWT, generateCredentialsFilename } from '../src/utils';
@ -37,20 +49,10 @@ describe('Utils', () => {
); );
const body = JSON.parse(val); const body = JSON.parse(val);
expect(body.iss).to.eq(tc.serviceAccount); assert.deepStrictEqual(body.iss, tc.serviceAccount);
expect(body.aud).to.eq('https://oauth2.googleapis.com/token'); assert.deepStrictEqual(body.aud, 'https://oauth2.googleapis.com/token');
assert.deepStrictEqual(body.sub, tc.subject);
if (tc.subject) { assert.deepStrictEqual(body.scope, tc.scopes?.join(' '));
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;
}
}); });
}); });
}); });
@ -59,7 +61,7 @@ describe('Utils', () => {
it('returns a string matching the regex', () => { it('returns a string matching the regex', () => {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
const filename = generateCredentialsFilename(); const filename = generateCredentialsFilename();
expect(filename).to.match(/gha-creds-[0-9a-z]{16}\.json/); assert.match(filename, /gha-creds-[0-9a-z]{16}\.json/);
} }
}); });
}); });