ken_nogi/NodeSrv/apps/lineworks-user-auth/test/tokenCrypto.test.js
Kenichiro NOGI ce58cb4be4 初回コミット: dev配下(NodeSrv/Pleasanter等)をGitea管理下に統合
GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。
NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは
別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter
インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:37:06 +09:00

26 lines
935 B
JavaScript

const { test } = require("node:test");
const assert = require("node:assert");
const crypto = require("node:crypto");
const { encrypt, decrypt } = require("../src/lib/tokenCrypto");
const KEY_HEX = crypto.randomBytes(32).toString("hex");
test("encrypt then decrypt returns the original plain text", () => {
const plain = "sample-access-token-value";
const encrypted = encrypt(plain, KEY_HEX);
assert.notStrictEqual(encrypted, plain);
assert.strictEqual(decrypt(encrypted, KEY_HEX), plain);
});
test("encrypt output contains iv, authTag, cipherText separated by colons", () => {
const encrypted = encrypt("abc", KEY_HEX);
const parts = encrypted.split(":");
assert.strictEqual(parts.length, 3);
});
test("decrypt throws when the key does not match", () => {
const encrypted = encrypt("abc", KEY_HEX);
const otherKey = crypto.randomBytes(32).toString("hex");
assert.throws(() => decrypt(encrypted, otherKey));
});