Skip to content

Commit

Permalink
Merge pull request #22 from OpenSecretCloud/remove-invite-code
Browse files Browse the repository at this point in the history
Remove invite code from tests
  • Loading branch information
AnthonyRonning authored Jan 31, 2025
2 parents 86c27fb + 3667fb5 commit 6141272
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
const TEST_EMAIL = process.env.VITE_TEST_EMAIL;
const TEST_PASSWORD = process.env.VITE_TEST_PASSWORD;
const TEST_NAME = process.env.VITE_TEST_NAME;
const TEST_INVITE_CODE = process.env.VITE_TEST_INVITE_CODE;

if (!TEST_EMAIL || !TEST_PASSWORD || !TEST_NAME || !TEST_INVITE_CODE) {
if (!TEST_EMAIL || !TEST_PASSWORD || !TEST_NAME) {
throw new Error("Test credentials must be set in .env.local");
}

Expand All @@ -27,7 +26,7 @@ async function tryEmailLogin() {
} catch (error) {
console.warn(error);
console.log("Login failed, attempting signup");
await fetchSignUp(TEST_EMAIL!, TEST_PASSWORD!, TEST_INVITE_CODE!, TEST_NAME!);
await fetchSignUp(TEST_EMAIL!, TEST_PASSWORD!, "", TEST_NAME!);
return await fetchLogin(TEST_EMAIL!, TEST_PASSWORD!);
}
}
Expand Down Expand Up @@ -62,7 +61,7 @@ test("Logout doesn't error", async () => {

test("Guest signup and login flow", async () => {
// Sign up as guest
const guestSignup = await fetchGuestSignUp(TEST_PASSWORD!, TEST_INVITE_CODE!);
const guestSignup = await fetchGuestSignUp(TEST_PASSWORD!, "");
expect(guestSignup.id).toBeDefined();
expect(guestSignup.email).toBeNull();
expect(guestSignup.access_token).toBeDefined();
Expand Down Expand Up @@ -129,7 +128,7 @@ test("Guest signup and login flow", async () => {

test("Guest refresh token works", async () => {
// Sign up as guest
const guestSignup = await fetchGuestSignUp(TEST_PASSWORD!, TEST_INVITE_CODE!);
const guestSignup = await fetchGuestSignUp(TEST_PASSWORD!, "");
const guestLogin = await fetchGuestLogin(guestSignup.id, TEST_PASSWORD!);

// Set tokens for authenticated requests
Expand All @@ -148,7 +147,7 @@ test("Guest refresh token works", async () => {

test("Guest logout doesn't error", async () => {
// Sign up as guest
const guestSignup = await fetchGuestSignUp(TEST_PASSWORD!, TEST_INVITE_CODE!);
const guestSignup = await fetchGuestSignUp(TEST_PASSWORD!, "");
const { refresh_token } = await fetchGuestLogin(guestSignup.id, TEST_PASSWORD!);
await fetchLogout(refresh_token);
});
Expand Down
22 changes: 21 additions & 1 deletion src/lib/signing.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from "bun:test";
import { expect, test, beforeEach } from "bun:test";
import { fetchLogin, signMessage, fetchPublicKey, fetchPrivateKeyBytes } from "./api";
import { bytesToHex } from "./test/utils";
import { sha256 } from '@noble/hashes/sha256';
Expand All @@ -8,11 +8,29 @@ const TEST_EMAIL = process.env.VITE_TEST_EMAIL;
const TEST_PASSWORD = process.env.VITE_TEST_PASSWORD;

async function setupTestUser() {
// Clear any existing tokens first
window.localStorage.clear();

// Get fresh tokens
const { access_token, refresh_token } = await fetchLogin(TEST_EMAIL!, TEST_PASSWORD!);
window.localStorage.setItem("access_token", access_token);
window.localStorage.setItem("refresh_token", refresh_token);

// Add a small delay to ensure tokens are properly set
await new Promise(resolve => setTimeout(resolve, 100));

// Verify tokens were set correctly
const storedToken = window.localStorage.getItem("access_token");
if (!storedToken) {
throw new Error("Failed to set access token");
}
}

// Clean up before each test
beforeEach(async () => {
window.localStorage.clear();
});

test("Sign message with Schnorr returns valid signature", async () => {
await setupTestUser();

Expand Down Expand Up @@ -90,6 +108,8 @@ test("Sign message with ECDSA returns valid signature", async () => {
});

test("Private key endpoints with derivation paths", async () => {
// Clear any existing tokens and set up fresh ones
window.localStorage.clear();
await setupTestUser();

// Test getting private key bytes without derivation path
Expand Down

0 comments on commit 6141272

Please sign in to comment.