Skip to content

Commit

Permalink
test(integration): used token auth for registry interactions rather t…
Browse files Browse the repository at this point in the history
…han legacy auth
  • Loading branch information
travi committed Dec 18, 2022
1 parent 0973513 commit caa8b95
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
21 changes: 14 additions & 7 deletions test/helpers/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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';
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.
Expand Down Expand Up @@ -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.
Expand Down
25 changes: 13 additions & 12 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 () => {
Expand Down

0 comments on commit caa8b95

Please sign in to comment.