Skip to content

Commit f116cb4

Browse files
authoredMar 1, 2021
feat: verify if vsce pat is valid or not (#105)
This also bumps the minimum version of `vsce` to 1.85.1, which is where the required command was added. Fixes #89
1 parent dbc9e87 commit f116cb4

8 files changed

+13644
-93
lines changed
 

‎lib/set-auth.js

-10
This file was deleted.

‎lib/verify-auth.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const execa = require('execa');
2+
const SemanticReleaseError = require('@semantic-release/error');
3+
4+
module.exports = async (logger) => {
5+
logger.log('Verify authentication for vsce');
6+
const { VSCE_TOKEN } = process.env;
7+
8+
if (!VSCE_TOKEN) {
9+
throw new SemanticReleaseError('No vsce personal access token specified (set the "VSCE_TOKEN" environment variable).', 'ENOVSCEPAT');
10+
}
11+
12+
try {
13+
execa.sync('vsce', ['verify-pat', '--pat', VSCE_TOKEN]);
14+
} catch (e) {
15+
throw new SemanticReleaseError(`Invalid vsce token. Additional information:\n\n${e}`, 'EINVALIDVSCETOKEN');
16+
}
17+
};

‎lib/verify.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const verifyPkg = require('./verify-pkg');
2-
const setAuth = require('./set-auth');
2+
const verifyAuth = require('./verify-auth');
33
const getPkg = require('read-pkg-up');
44
const SemanticReleaseError = require('@semantic-release/error');
55

@@ -12,10 +12,6 @@ module.exports = async logger => {
1212
);
1313
}
1414
verifyPkg(packageJson);
15-
await setAuth(logger);
16-
try {
17-
// TODO: Verify output
18-
} catch (err) {
19-
throw new SemanticReleaseError('Invalid vsce token.', 'EINVALIDVSCETOKEN');
20-
}
15+
16+
verifyAuth(logger);
2117
};

‎package-lock.json

+13,585-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"execa": "^5.0.0",
6262
"fs-extra": "^9.0.1",
6363
"read-pkg-up": "^7.0.1",
64-
"vsce": "^1.73.0"
64+
"vsce": "^1.85.1"
6565
},
6666
"peerDependencies": {
6767
"semantic-release": ">=16.0.0"

‎test/set-auth.test.js

-18
This file was deleted.

‎test/verify-auth.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const test = require('ava');
2+
const sinon = require('sinon');
3+
const execa = require('execa');
4+
const SemanticReleaseError = require('@semantic-release/error');
5+
const verifyAuth = require('../lib/verify-auth');
6+
7+
const logger = {
8+
log: sinon.fake()
9+
};
10+
11+
sinon.stub(execa, 'sync').withArgs('vsce', ['verify-pat', '--pat', process.env.VSCE_TOKEN]).returns();
12+
13+
test('VSCE_TOKEN is set', async t => {
14+
process.env.VSCE_TOKEN = 'abc123';
15+
16+
await t.notThrowsAsync(() => verifyAuth(logger));
17+
});
18+
19+
test('VSCE_TOKEN is not set', async t => {
20+
delete process.env.VSCE_TOKEN;
21+
22+
await t.throwsAsync(() => verifyAuth(logger), { instanceOf: SemanticReleaseError, code: 'ENOVSCEPAT' });
23+
});
24+
25+
test('VSCE_TOKEN is valid', async t => {
26+
process.env.VSCE_TOKEN = 'abc123';
27+
28+
await t.notThrowsAsync(() => verifyAuth(logger));
29+
});
30+
31+
test('VSCE_TOKEN is invalid', async t => {
32+
process.env.VSCE_TOKEN = 'abc123';
33+
execa.sync.restore();
34+
35+
await t.throwsAsync(() => verifyAuth(logger), { instanceOf: SemanticReleaseError, code: 'EINVALIDVSCETOKEN' });
36+
});

‎test/verify.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const logger = {
99

1010
test('package.json is found', async t => {
1111
const verify = proxyquire('../lib/verify', {
12-
'./set-auth': sinon.stub().resolves(),
12+
'./verify-auth': sinon.stub().resolves(),
1313
'./verify-pkg': sinon.stub(),
1414
'read-pkg-up': sinon.stub().returns({ packageJson: {} })
1515
});
@@ -19,7 +19,7 @@ test('package.json is found', async t => {
1919

2020
test('package.json is not found', async t => {
2121
const verify = proxyquire('../lib/verify', {
22-
'./set-auth': sinon.stub().resolves(),
22+
'./verify-auth': sinon.stub().resolves(),
2323
'./verify-pkg': sinon.stub(),
2424
'read-pkg-up': sinon.stub().returns({ })
2525
});

0 commit comments

Comments
 (0)
Please sign in to comment.