mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-23 14:17:06 +00:00
feat(puter-js): team members carry passwordPending for the owner (#4646)
Benchmarks / changes (push) Canceled after 0s
Benchmarks / bench shard 1/3 (push) Canceled after 0s
Benchmarks / bench shard 2/3 (push) Canceled after 0s
Benchmarks / bench shard 3/3 (push) Canceled after 0s
Benchmarks / benchmarks (push) Canceled after 0s
Backend Tests / changes (push) Canceled after 0s
Backend Tests / typecheck (push) Canceled after 0s
Backend Tests / test shard 1/4 (push) Canceled after 0s
Backend Tests / test shard 2/4 (push) Canceled after 0s
Backend Tests / test shard 3/4 (push) Canceled after 0s
Backend Tests / test shard 4/4 (push) Canceled after 0s
Backend Tests / test (main) (push) Canceled after 0s
Backend Tests / coverage (push) Canceled after 0s
Notify HeyPuter / notify (push) Canceled after 0s
Benchmarks / changes (push) Canceled after 0s
Benchmarks / bench shard 1/3 (push) Canceled after 0s
Benchmarks / bench shard 2/3 (push) Canceled after 0s
Benchmarks / bench shard 3/3 (push) Canceled after 0s
Benchmarks / benchmarks (push) Canceled after 0s
Backend Tests / changes (push) Canceled after 0s
Backend Tests / typecheck (push) Canceled after 0s
Backend Tests / test shard 1/4 (push) Canceled after 0s
Backend Tests / test shard 2/4 (push) Canceled after 0s
Backend Tests / test shard 3/4 (push) Canceled after 0s
Backend Tests / test shard 4/4 (push) Canceled after 0s
Backend Tests / test (main) (push) Canceled after 0s
Backend Tests / coverage (push) Canceled after 0s
Notify HeyPuter / notify (push) Canceled after 0s
* feat(puter-js): team members carry passwordPending for the owner * test(puter-js): team members' passwordPending in the teams API suite * test(puter-js): passwordPending wording, non-boolean inputs, and the member view's account shape * docs(puter-js): one-line passwordPending description * docs(puter-js): listMembers description covers the owner's passwordPending --------- Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
This commit is contained in:
1 parent
7e419e722f
commit
9e102909d9
5 files changed
+96
-5
No files matched your search
@@ -45,6 +45,8 @@ export function toMember (row) {
|
||||
...(typeof row.created_at === 'string' ? { createdAt: row.created_at } : {}),
|
||||
// Owners only, and what billing keys a seat's plan on.
|
||||
...(typeof row.uuid === 'string' ? { uuid: row.uuid } : {}),
|
||||
// Owners only; true until the account sets its own password.
|
||||
...(typeof row.password_pending === 'boolean' ? { passwordPending: row.password_pending } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import { mapListResult, toMember } from './lib/shapes.js';
|
||||
* Returns the accounts belonging to a team. Any member may call it. From an
|
||||
* app it needs the team's directory open (else `team_not_found`), lists
|
||||
* active accounts only, and never carries `uuid`. The response carries no
|
||||
* email, activation state or usage.
|
||||
* email or usage, and only the team owner gets `passwordPending`.
|
||||
*
|
||||
* @this {import('./index.js').TeamsModule}
|
||||
* @param {string} uid
|
||||
|
||||
@@ -133,6 +133,27 @@ describe('list forms', () => {
|
||||
expect('uuid' in member).toBe(false);
|
||||
});
|
||||
|
||||
it('carries passwordPending when the row has it, true or false', async () => {
|
||||
routes({ 'GET /teams/t-1/members': { items: [
|
||||
{ username: 'ann', org_owned: true, created_at: 'x', uuid: 'u-1', password_pending: true },
|
||||
{ username: 'bob', org_owned: false, created_at: 'x', uuid: 'u-2', password_pending: false },
|
||||
{ username: 'cat', org_owned: true, created_at: 'x' },
|
||||
] } });
|
||||
const [ann, bob, cat] = await teams.listMembers('t-1');
|
||||
expect(ann.passwordPending).toBe(true);
|
||||
expect(bob.passwordPending).toBe(false);
|
||||
expect('passwordPending' in cat).toBe(false);
|
||||
});
|
||||
|
||||
it('drops a non-boolean password_pending rather than coercing it', async () => {
|
||||
routes({ 'GET /teams/t-1/members': { items: [1, 'true', null].map((value, i) => (
|
||||
{ username: `u${i}`, org_owned: true, created_at: 'x', password_pending: value }
|
||||
)) } });
|
||||
const members = await teams.listMembers('t-1');
|
||||
expect(members).toHaveLength(3);
|
||||
for (const m of members) expect('passwordPending' in m).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps a false orgOwned for an account caller', async () => {
|
||||
routes({ 'GET /teams/t-1/members': { items: [
|
||||
{ username: 'ann', org_owned: false, created_at: 'x', uuid: 'u-1' },
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
* @property {string} [createdAt] When the account joined the team. Absent when an app calls.
|
||||
* @property {string} [uuid] Present only when the team owner calls with their own session or
|
||||
* API token; billing keys a seat's plan on it.
|
||||
* @property {boolean} [passwordPending] True until the account sets its own password; sent to the team owner only.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { suite } from '../harness/types.ts';
|
||||
import type {
|
||||
SuiteTest,
|
||||
SuiteTestSpec,
|
||||
TestContext,
|
||||
} from '../harness/types.ts';
|
||||
@@ -15,12 +14,16 @@ const CLIENT_SIDE = new Set([
|
||||
]);
|
||||
|
||||
const needsTeams = (
|
||||
tests: Record<string, SuiteTest>,
|
||||
tests: Record<string, SuiteTestSpec>,
|
||||
): Record<string, SuiteTestSpec> =>
|
||||
Object.fromEntries(
|
||||
Object.entries(tests).map(([name, fn]) => [
|
||||
Object.entries(tests).map(([name, spec]) => [
|
||||
name,
|
||||
CLIENT_SIDE.has(name) ? fn : { requires: ['teams'], fn },
|
||||
CLIENT_SIDE.has(name)
|
||||
? spec
|
||||
: typeof spec === 'function'
|
||||
? { requires: ['teams'], fn: spec }
|
||||
: { ...spec, requires: ['teams', ...(spec.requires ?? [])] },
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -166,6 +169,70 @@ export default suite('teams', needsTeams({
|
||||
);
|
||||
},
|
||||
|
||||
'listMembers tells the owner which seats still have a password to set': async (t) => {
|
||||
const team = await makeTeam(t, 'pending');
|
||||
const username = `tsp${tag()}`;
|
||||
await t.puter.teams.createMember(team.uid, { username });
|
||||
|
||||
const members = (await t.puter.teams.listMembers(team.uid)) as Array<{
|
||||
username: string; passwordPending?: boolean;
|
||||
}>;
|
||||
const seat = members.find((m) => m.username === username);
|
||||
const owner = members.find((m) => m.username === t.env.users.user.username);
|
||||
t.assert.equal(seat?.passwordPending, true);
|
||||
t.assert.equal(owner?.passwordPending, false);
|
||||
},
|
||||
|
||||
"a member's listMembers carries no passwordPending": {
|
||||
// Sends the seat's session cookie by hand, which a browser page cannot.
|
||||
platforms: ['node', 'workerd'],
|
||||
fn: async (t) => {
|
||||
const team = await makeTeam(t, 'member-view');
|
||||
const username = `tsv${tag()}`;
|
||||
const { temporaryPassword } = (await t.puter.teams.createMember(team.uid, {
|
||||
username,
|
||||
})) as { temporaryPassword: string };
|
||||
|
||||
const login = await fetch(`${t.env.origin}/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Origin: t.env.origin },
|
||||
body: JSON.stringify({ username, password: temporaryPassword }),
|
||||
});
|
||||
t.assert.ok(login.ok, `seat login failed: ${login.status}`);
|
||||
// The body carries a GUI token; the change-password gate wants the session cookie's.
|
||||
const setCookies = login.headers.getSetCookie?.() ?? [login.headers.get('set-cookie') ?? ''];
|
||||
const cookie = setCookies.find((c) => /httponly/iu.test(c))?.split(';')[0] ?? '';
|
||||
const token = cookie.slice(cookie.indexOf('=') + 1);
|
||||
t.assert.ok(cookie.includes('=') && token.length > 0, 'login should set a session cookie');
|
||||
|
||||
const changed = await fetch(`${t.env.origin}/user-protected/change-password`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Origin: t.env.origin,
|
||||
Authorization: `Bearer ${token}`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
body: JSON.stringify({ password: temporaryPassword, new_pass: `seat-${tag()}-${tag()}` }),
|
||||
});
|
||||
t.assert.ok(changed.ok, `password change failed: ${changed.status}`);
|
||||
|
||||
t.puter.setAuthToken(token);
|
||||
try {
|
||||
const members = (await t.puter.teams.listMembers(team.uid)) as Array<Record<string, unknown>>;
|
||||
t.assert.ok(members.length > 0, 'the member should see the roster');
|
||||
for (const m of members) {
|
||||
// orgOwned shows the account view was served, not the username-only app view.
|
||||
t.assert.equal(typeof m.orgOwned, 'boolean');
|
||||
t.assert.ok(!('uuid' in m), `${String(m.username)} should carry no uuid`);
|
||||
t.assert.ok(!('passwordPending' in m), `${String(m.username)} should carry no passwordPending`);
|
||||
}
|
||||
} finally {
|
||||
t.puter.setAuthToken(t.env.users.user.token);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
'createMember with a taken username rejects': async (t) => {
|
||||
const team = await makeTeam(t, 'taken');
|
||||
await t.assert.rejects(
|
||||
|
||||
Reference in new issue
Block a user