test: cover explicit import token handling
This commit is contained in:
parent
82494e94fd
commit
37e6a2ad5a
1 changed files with 57 additions and 0 deletions
|
|
@ -134,6 +134,63 @@ test('repo import-batch preserves successful batch output', async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('repo import-batch sends an explicit GitHub token without printing it', async () => {
|
||||||
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'stoke-import-batch-token-'));
|
||||||
|
const configFile = path.join(dir, 'config.json');
|
||||||
|
const manifestFile = path.join(dir, 'manifest.json');
|
||||||
|
const emptyPath = path.join(dir, 'bin');
|
||||||
|
const sourceToken = 'github-token-must-not-be-printed';
|
||||||
|
const { server, requests } = await startMigrationServer();
|
||||||
|
fs.mkdirSync(emptyPath);
|
||||||
|
fs.writeFileSync(configFile, JSON.stringify({
|
||||||
|
url: `http://127.0.0.1:${server.address().port}`,
|
||||||
|
login: 'destination',
|
||||||
|
token: 'forge-token-must-not-be-printed',
|
||||||
|
}));
|
||||||
|
fs.writeFileSync(manifestFile, JSON.stringify([{
|
||||||
|
name: 'from-github',
|
||||||
|
from: 'https://github.com/source/repository.git',
|
||||||
|
service: 'github',
|
||||||
|
github_token: sourceToken,
|
||||||
|
}]));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await run(
|
||||||
|
['--config', configFile, 'repo', 'import-batch', '--file', manifestFile],
|
||||||
|
{ PATH: emptyPath, GITHUB_TOKEN: undefined },
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(result.status, 0, result.stderr);
|
||||||
|
assert.equal(result.stderr, '');
|
||||||
|
assert.equal(result.stdout,
|
||||||
|
'Imported: destination/from-github -> https://forge.test/destination/from-github\n'
|
||||||
|
+ '\nBatch complete: 1/1 imported.\n');
|
||||||
|
assert.deepEqual(requests, [{
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/v1/repos/migrate',
|
||||||
|
body: {
|
||||||
|
clone_addr: 'https://github.com/source/repository.git',
|
||||||
|
repo_name: 'from-github',
|
||||||
|
repo_owner: 'destination',
|
||||||
|
service: 'github',
|
||||||
|
private: false,
|
||||||
|
issues: true,
|
||||||
|
labels: true,
|
||||||
|
milestones: true,
|
||||||
|
pull_requests: true,
|
||||||
|
releases: true,
|
||||||
|
wiki: true,
|
||||||
|
lfs: false,
|
||||||
|
auth_token: sourceToken,
|
||||||
|
},
|
||||||
|
}]);
|
||||||
|
assert.doesNotMatch(result.stdout + result.stderr, new RegExp(sourceToken));
|
||||||
|
} finally {
|
||||||
|
await new Promise((resolve) => server.close(resolve));
|
||||||
|
fs.rmSync(dir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('repo import-batch keeps file and JSON errors at batch level', async () => {
|
test('repo import-batch keeps file and JSON errors at batch level', async () => {
|
||||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'stoke-import-batch-invalid-'));
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'stoke-import-batch-invalid-'));
|
||||||
const configFile = path.join(dir, 'config.json');
|
const configFile = path.join(dir, 'config.json');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue