Skip to content

Commit caa8b95

Browse files
committed
test(integration): used token auth for registry interactions rather than legacy auth
1 parent 0973513 commit caa8b95

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

test/helpers/npm-registry.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import got from 'got';
66
import delay from 'delay';
77
import pRetry from 'p-retry';
88

9-
const IMAGE = 'verdaccio/verdaccio:4';
9+
const IMAGE = 'verdaccio/verdaccio:5';
1010
const REGISTRY_PORT = 4873;
1111
const REGISTRY_HOST = 'localhost';
1212
const NPM_USERNAME = 'integration';
1313
const NPM_PASSWORD = 'suchsecure';
1414
const NPM_EMAIL = 'integration@test.com';
1515
const docker = new Docker();
1616
const __dirname = dirname(fileURLToPath(import.meta.url));
17-
let container;
17+
let container, npmToken;
1818

1919
/**
2020
* Download the `npm-registry-docker` Docker image, create a new container and start it.
@@ -55,16 +55,23 @@ export async function start() {
5555
email: NPM_EMAIL,
5656
},
5757
});
58+
59+
// Create token for user
60+
({token: npmToken} = await got(`http://${REGISTRY_HOST}:${REGISTRY_PORT}/-/npm/v1/tokens`, {
61+
username: NPM_USERNAME,
62+
password: NPM_PASSWORD,
63+
method: 'POST',
64+
headers: {'content-type': 'application/json'},
65+
json: {password: NPM_PASSWORD, readonly: false, cidr_whitelist: []}
66+
}).json());
5867
}
5968

6069
export const url = `http://${REGISTRY_HOST}:${REGISTRY_PORT}/`;
6170

62-
export const authEnv = {
71+
export const authEnv = () => ({
6372
npm_config_registry: url, // eslint-disable-line camelcase
64-
NPM_USERNAME,
65-
NPM_PASSWORD,
66-
NPM_EMAIL,
67-
};
73+
NPM_TOKEN: npmToken,
74+
});
6875

6976
/**
7077
* Stop and remote the `npm-registry-docker` Docker container.

test/integration.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,13 @@ const { readJson, writeJson } = fsExtra;
3131

3232
// Environment variables used with semantic-release cli (similar to what a user would setup)
3333
const { GITHUB_ACTION, GITHUB_ACTIONS, GITHUB_TOKEN, ...processEnvWithoutGitHubActionsVariables } = process.env;
34-
const env = {
35-
...processEnvWithoutGitHubActionsVariables,
36-
...npmRegistry.authEnv,
37-
CI: "true",
38-
GH_TOKEN: gitbox.gitCredential,
39-
TRAVIS: "true",
40-
TRAVIS_BRANCH: "master",
41-
TRAVIS_PULL_REQUEST: "false",
42-
GITHUB_API_URL: mockServer.url,
43-
};
34+
let env;
4435

4536
// Environment variables used only for the local npm command used to do verification
4637
const npmTestEnv = {
4738
...process.env,
48-
...npmRegistry.authEnv,
39+
...npmRegistry.authEnv(),
4940
npm_config_registry: npmRegistry.url,
50-
LEGACY_TOKEN: Buffer.from(`${env.NPM_USERNAME}:${env.NPM_PASSWORD}`, "utf8").toString("base64"),
5141
};
5242

5343
const cli = path.resolve("./bin/semantic-release.js");
@@ -57,6 +47,17 @@ const pluginLogEnv = path.resolve("./test/fixtures/plugin-log-env");
5747

5848
test.before(async () => {
5949
await Promise.all([gitbox.start(), npmRegistry.start(), mockServer.start()]);
50+
51+
env = {
52+
...processEnvWithoutGitHubActionsVariables,
53+
...npmRegistry.authEnv(),
54+
CI: "true",
55+
GH_TOKEN: gitbox.gitCredential,
56+
TRAVIS: "true",
57+
TRAVIS_BRANCH: "master",
58+
TRAVIS_PULL_REQUEST: "false",
59+
GITHUB_API_URL: mockServer.url,
60+
};
6061
});
6162

6263
test.after.always(async () => {

0 commit comments

Comments
 (0)