test(integration): used token auth for registry interactions rather than legacy auth

This commit is contained in:
Matt Travi 2022-12-17 22:53:11 -06:00
parent 097351304e
commit caa8b95f7b
No known key found for this signature in database
GPG Key ID: CB62529BDFD29894
2 changed files with 27 additions and 19 deletions

View File

@ -6,7 +6,7 @@ import got from 'got';
import delay from 'delay';
import pRetry from 'p-retry';
const IMAGE = 'verdaccio/verdaccio:4';
const IMAGE = 'verdaccio/verdaccio:5';
const REGISTRY_PORT = 4873;
const REGISTRY_HOST = 'localhost';
const NPM_USERNAME = 'integration';
@ -14,7 +14,7 @@ const NPM_PASSWORD = 'suchsecure';
const NPM_EMAIL = 'integration@test.com';
const docker = new Docker();
const __dirname = dirname(fileURLToPath(import.meta.url));
let container;
let container, npmToken;
/**
* Download the `npm-registry-docker` Docker image, create a new container and start it.
@ -55,16 +55,23 @@ export async function start() {
email: NPM_EMAIL,
},
});
// Create token for user
({token: npmToken} = await got(`http://${REGISTRY_HOST}:${REGISTRY_PORT}/-/npm/v1/tokens`, {
username: NPM_USERNAME,
password: NPM_PASSWORD,
method: 'POST',
headers: {'content-type': 'application/json'},
json: {password: NPM_PASSWORD, readonly: false, cidr_whitelist: []}
}).json());
}
export const url = `http://${REGISTRY_HOST}:${REGISTRY_PORT}/`;
export const authEnv = {
export const authEnv = () => ({
npm_config_registry: url, // eslint-disable-line camelcase
NPM_USERNAME,
NPM_PASSWORD,
NPM_EMAIL,
};
NPM_TOKEN: npmToken,
});
/**
* Stop and remote the `npm-registry-docker` Docker container.

View File

@ -31,23 +31,13 @@ const { readJson, writeJson } = fsExtra;
// Environment variables used with semantic-release cli (similar to what a user would setup)
const { GITHUB_ACTION, GITHUB_ACTIONS, GITHUB_TOKEN, ...processEnvWithoutGitHubActionsVariables } = process.env;
const env = {
...processEnvWithoutGitHubActionsVariables,
...npmRegistry.authEnv,
CI: "true",
GH_TOKEN: gitbox.gitCredential,
TRAVIS: "true",
TRAVIS_BRANCH: "master",
TRAVIS_PULL_REQUEST: "false",
GITHUB_API_URL: mockServer.url,
};
let env;
// Environment variables used only for the local npm command used to do verification
const npmTestEnv = {
...process.env,
...npmRegistry.authEnv,
...npmRegistry.authEnv(),
npm_config_registry: npmRegistry.url,
LEGACY_TOKEN: Buffer.from(`${env.NPM_USERNAME}:${env.NPM_PASSWORD}`, "utf8").toString("base64"),
};
const cli = path.resolve("./bin/semantic-release.js");
@ -57,6 +47,17 @@ const pluginLogEnv = path.resolve("./test/fixtures/plugin-log-env");
test.before(async () => {
await Promise.all([gitbox.start(), npmRegistry.start(), mockServer.start()]);
env = {
...processEnvWithoutGitHubActionsVariables,
...npmRegistry.authEnv(),
CI: "true",
GH_TOKEN: gitbox.gitCredential,
TRAVIS: "true",
TRAVIS_BRANCH: "master",
TRAVIS_PULL_REQUEST: "false",
GITHUB_API_URL: mockServer.url,
};
});
test.after.always(async () => {