Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

- fix: a user created without names reads back, lists and logs in on mysql
- fix: file stores draw permission ids from one sequence, and renumber repeated ids at startup
- fix: file store user, group and permission reads hide revoked permissions, and a regrant gets a new id
- fix: reject create conflicts and duplicate permission targets
Expand Down
3 changes: 3 additions & 0 deletions lib/user/store/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { splitQualifiedUsername } from '../qualified.js'

const userDbMap = { id: 'nt_user_id', gid: 'nt_group_id' }
const boolFields = ['is_admin', 'deleted']
const nullableFields = ['first_name', 'last_name']

class UserRepoMySQL extends UserBase {
constructor(args = {}) {
Expand Down Expand Up @@ -61,6 +62,7 @@ class UserRepoMySQL extends UserBase {
for (const b of ['is_admin']) {
if (u[b] !== undefined) u[b] = u[b] === 1 // int to boolean
}
for (const f of nullableFields) if (u[f] === null) delete u[f]
const g = {
id: u.nt_group_id,
name: groupName,
Expand Down Expand Up @@ -166,6 +168,7 @@ class UserRepoMySQL extends UserBase {
for (const b of boolFields) {
r[b] = r[b] === 1
}
for (const f of nullableFields) if (r[f] === null) delete r[f]
if ([false, undefined].includes(origDeleted)) delete r.deleted

const effectivePerm = await Permission.getEffective(r.id)
Expand Down
48 changes: 48 additions & 0 deletions routes/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ before(async () => {
})

let userId2
const namelessUsername = `${userCase.username}3`

after(async () => {
if (userId2) await User.destroy({ id: userId2 })
for (const deleted of [false, true]) {
for (const u of await User.get({ username: namelessUsername, gid: userCase.gid, deleted }))
await User.destroy({ id: u.id })
}
await server.stop()
})

Expand Down Expand Up @@ -123,6 +128,49 @@ describe('user routes', () => {
assert.ok([200, 204].includes(res.statusCode))
})

it('a user created without names can be read, listed and logged in', async () => {
const testCase = JSON.parse(JSON.stringify(userCase))
delete testCase.id
delete testCase.deleted
delete testCase.first_name
delete testCase.last_name
testCase.username = namelessUsername

const created = await server.inject({
method: 'POST',
url: '/user',
headers: auth.headers,
payload: testCase,
})
assert.equal(created.statusCode, 201)
const id = created.result.user[0].id
assert.equal(created.result.user[0].first_name, undefined)

const one = await server.inject({ method: 'GET', url: `/user/${id}`, headers: auth.headers })
assert.equal(one.statusCode, 200)

const list = await server.inject({
method: 'GET',
url: `/user?gid=${userCase.gid}`,
headers: auth.headers,
})
assert.equal(list.statusCode, 200)
assert.ok(list.result.user.some((u) => u.id === id))

const login = await server.inject({
method: 'POST',
url: '/session',
payload: { username: `${testCase.username}@${groupCase.name}`, password: testCase.password },
})
assert.equal(login.statusCode, 200)
assert.equal(login.result.user.id, id)

const headers = { Authorization: `Bearer ${login.result.session.token}` }
const session = await server.inject({ method: 'GET', url: '/session', headers })
assert.equal(session.statusCode, 200)
await server.inject({ method: 'DELETE', url: '/session', headers })
})

it('DELETE /session', async () => {
const res = await server.inject({
method: 'DELETE',
Expand Down
Loading