import assert from "node:assert/strict";
import { test } from "node:test";
import { resolveNetwork } from "../src/auth.js";

test("auth disabled when password unset/empty -> always local", () => {
  assert.equal(resolveNetwork(undefined, undefined), "global");
  assert.equal(resolveNetwork("anything", undefined), "global");
  assert.equal(resolveNetwork(undefined, ""), "global");
  assert.equal(resolveNetwork("anything", ""), "global");
});

test("password set: exact match -> local", () => {
  assert.equal(resolveNetwork("s3cr3t", "s3cr3t"), "global");
});

test("password set: mismatch -> null", () => {
  assert.equal(resolveNetwork("wrong", "s3cr3t"), null);
});

test("password set: missing secret -> null", () => {
  assert.equal(resolveNetwork(undefined, "s3cr3t"), null);
});

test("password set: length-mismatched secret -> null (constant-time compare)", () => {
  assert.equal(resolveNetwork("s3cr3", "s3cr3t"), null);
  assert.equal(resolveNetwork("s3cr3tt", "s3cr3t"), null);
  assert.equal(resolveNetwork("", "s3cr3t"), null);
});
