Skip to content
Snippets Groups Projects
Unverified Commit c9d56632 authored by Thomas SAUVAGE's avatar Thomas SAUVAGE
Browse files

Fix create user, probably

parent f89e3662
No related branches found
No related tags found
1 merge request!4Trying to implement openid
Pipeline #13836 passed
......@@ -21,6 +21,8 @@ export const loginNotSigmaUser = async ({ request, response, auth }: HttpContext
export const createNotSigmaUser = async ({ request, response }: HttpContextContract) => {
// TODO: Validate ?
const username = request.input('username')
const name = request.input('name')
const password = randomString(20)
// Check if user already exists
......@@ -30,9 +32,9 @@ export const createNotSigmaUser = async ({ request, response }: HttpContextContr
return response.badRequest({ error: 'User already exists' })
}
await User.create({ username, password })
await User.create({ username, name, password, groups: [], isAdmin: false, isSigmaUser: false })
return response.created({ message: 'User created', username, password })
return response.created({ message: 'User created', username, name, password })
}
/** Remove an auth token */
......
......@@ -15,6 +15,7 @@ const clientOptions: ClientMetadata = {
}
// ! Safe ? Works ? Risk of building up if people don't log in
// TODO: Make a DB, with a lifespan for each item
let verifiers: { [state: string]: string } = {}
/** Login a user using `auth.binets.fr` which uses OpenId auth */
......
......@@ -31,27 +31,3 @@ test('Invalid credential', async ({ client }) => {
})
response2.assertStatus(401)
})
test('Create user', async ({ client }) => {
const token = await getBearerToken(client, 'admin', '0000')
const response = await client
.post('/admin/notSigmaUser/create')
.bearerToken(token)
.json({
username: `test${Math.random()}`, // To avoid conflicts
})
response.assertStatus(201)
})
test('Create user without being admin', async ({ client }) => {
const token = await getBearerToken(client, 'thibaut', '0000')
const response = await client
.post('/admin/notSigmaUser/create')
.header('Authorization', `Bearer ${token}`)
.json({
username: 'test',
})
response.assertStatus(401)
})
import { test } from '@japa/runner'
import { getBearerToken } from '../test.utils'
test('Create user', async ({ client }) => {
const token = await getBearerToken(client, 'admin', '0000')
const response = await client
.post('/admin/notSigmaUser/create')
.bearerToken(token)
.json({
username: `test${Math.random()}`, // To avoid conflicts
})
response.assertStatus(201)
})
test('Create user without being admin', async ({ client }) => {
const token = await getBearerToken(client, 'thibaut', '0000')
const response = await client
.post('/admin/notSigmaUser/create')
.header('Authorization', `Bearer ${token}`)
.json({
username: 'test',
name: 'Tarte',
})
response.assertStatus(401)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment