From 37e6a2ad5a0141a344272004d0ef5c3d85d6de17 Mon Sep 17 00:00:00 2001 From: codex-bot-andresmgsl Date: Fri, 4 Sep 2026 07:31:26 +0000 Subject: [PATCH] test: cover explicit import token handling --- test/import-batch.test.js | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/import-batch.test.js b/test/import-batch.test.js index 16a96cf..cc7e46d 100644 --- a/test/import-batch.test.js +++ b/test/import-batch.test.js @@ -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 () => { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'stoke-import-batch-invalid-')); const configFile = path.join(dir, 'config.json');