Source commit: 6d1a121b0a8a636aac95998fe5d15c24c78eb7d0 Public tree identity: sha256:2bc22807f5b838286678b65d3f550b8ae4714ae673622041d4c2516a7c5b7926
72 lines
2.8 KiB
JavaScript
72 lines
2.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const assert = require("assert");
|
|
const cp = require("child_process");
|
|
const path = require("path");
|
|
|
|
const repo = path.resolve(__dirname, "..");
|
|
const coordinator = "https://coord.example.test";
|
|
const defaultHostedCoordinatorEndpoint = "https://clusterflux.michelpaulissen.com";
|
|
|
|
function clusterflux(args) {
|
|
return JSON.parse(
|
|
cp.execFileSync(
|
|
"cargo",
|
|
["run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--", ...args],
|
|
{ cwd: repo, encoding: "utf8" }
|
|
)
|
|
);
|
|
}
|
|
|
|
function clusterfluxRaw(args, env = {}) {
|
|
return cp.spawnSync(
|
|
"cargo",
|
|
["run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--", ...args],
|
|
{
|
|
cwd: repo,
|
|
encoding: "utf8",
|
|
env: {
|
|
...process.env,
|
|
...env,
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
const browser = clusterflux(["login", "--plan", "--coordinator", coordinator, "--json"]);
|
|
assert.strictEqual(browser.coordinator, coordinator);
|
|
assert(browser.human_flow.Browser, "browser login should be available for human users");
|
|
assert.strictEqual(browser.human_flow.Browser.authorization_url, null);
|
|
assert.strictEqual(browser.human_flow.Browser.server_owns_state, true);
|
|
assert.strictEqual(browser.human_flow.Browser.server_owns_nonce, true);
|
|
assert.strictEqual(browser.human_flow.Browser.pkce_required, true);
|
|
assert.strictEqual(browser.human_flow.Browser.hosted_callback, true);
|
|
assert.strictEqual(browser.human_flow.Browser.cli_receives_provider_authorization_code, false);
|
|
assert.strictEqual(browser.human_flow.Browser.cli_submits_identity_claims, false);
|
|
|
|
const defaultBrowser = clusterflux(["login", "--plan", "--json"]);
|
|
assert.strictEqual(defaultBrowser.coordinator, defaultHostedCoordinatorEndpoint);
|
|
assert(defaultBrowser.human_flow.Browser);
|
|
|
|
const nonInteractiveBrowser = clusterfluxRaw(
|
|
["login", "--browser", "--non-interactive", "--coordinator", coordinator, "--json"],
|
|
{
|
|
CLUSTERFLUX_BROWSER_OPEN_COMMAND:
|
|
"node -e 'require(\"fs\").writeFileSync(\"/tmp/clusterflux-browser-should-not-open\", \"opened\")'",
|
|
}
|
|
);
|
|
assert.strictEqual(nonInteractiveBrowser.status, 20, nonInteractiveBrowser.stderr);
|
|
assert.doesNotMatch(nonInteractiveBrowser.stderr, /Opening Clusterflux browser login/);
|
|
const nonInteractiveReport = JSON.parse(nonInteractiveBrowser.stdout);
|
|
assert.strictEqual(nonInteractiveReport.status, "authentication_required");
|
|
assert.strictEqual(nonInteractiveReport.non_interactive, true);
|
|
assert.strictEqual(nonInteractiveReport.browser_opened, false);
|
|
assert.strictEqual(nonInteractiveReport.machine_error.category, "authentication");
|
|
assert.strictEqual(nonInteractiveReport.machine_error.stable_exit_code, 20);
|
|
assert(
|
|
nonInteractiveReport.machine_error.next_actions.includes(
|
|
"rerun without --non-interactive to open the browser"
|
|
)
|
|
);
|
|
|
|
console.log("CLI login smoke passed");
|