-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Team endpoint middleware refactor (#625)
* Add db method to get user team role info * Update teamUserOnly middleware to get team user role info with new query * Update teamAdminOnly middleware to chain off teamUserOnly middleware * Add e2e seeder class in prep for adding e2e tests for middleware changes * Add teamUserOnly middleware unit tests * format go * Add unit tests for teamAdminOnly middleware
- Loading branch information
1 parent
a1614c6
commit 072183e
Showing
83 changed files
with
3,657 additions
and
1,344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,29 @@ | ||
import { ThunderdomeSeeder } from "./seeder"; | ||
|
||
const adminUser = { | ||
name: "E2E ADMIN", | ||
email: "[email protected]", | ||
password: "kentRules!", | ||
hashedPass: "$2a$10$3CvuzyoGIme3dJ4v9BnvyOIKFxEaYyjV2Lfunykv0VokGf/twxi9m", | ||
rank: "ADMIN", | ||
type: "ADMIN", | ||
}; | ||
|
||
const seed = async (pool) => { | ||
const newUser = await pool.query( | ||
`SELECT userid, verifyid FROM thunderdome.user_register($1, $2, $3, $4);`, | ||
[adminUser.name, adminUser.email, adminUser.hashedPass, adminUser.rank], | ||
const seeder = new ThunderdomeSeeder(pool); | ||
const { id } = await seeder.createUser( | ||
adminUser.name, | ||
adminUser.email, | ||
adminUser.type, | ||
true, | ||
); | ||
|
||
await pool.query("call thunderdome.user_account_verify($1);", [ | ||
newUser.rows[0].verifyid, | ||
]); | ||
const id = newUser.rows[0].userid; | ||
|
||
return { | ||
...adminUser, | ||
id, | ||
}; | ||
}; | ||
|
||
const teardown = async (pool) => { | ||
const oldUser = await pool.query( | ||
`SELECT id FROM thunderdome.users WHERE email = $1;`, | ||
[adminUser.email], | ||
); | ||
|
||
if (oldUser.rows.length) { | ||
await pool.query("DELETE FROM thunderdome.users WHERE id = $1;", [ | ||
oldUser.rows[0].id, | ||
]); | ||
} | ||
const seeder = new ThunderdomeSeeder(pool); | ||
await seeder.deleteUserByEmail(adminUser.email); | ||
|
||
return {}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,25 @@ | ||
import { ThunderdomeSeeder } from "./seeder"; | ||
|
||
export const adminAPIUser = { | ||
name: "E2E Admin API User", | ||
name: "E2EAdminAPIUser", | ||
email: "[email protected]", | ||
password: "kentRules!", | ||
hashedPass: "$2a$10$3CvuzyoGIme3dJ4v9BnvyOIKFxEaYyjV2Lfunykv0VokGf/twxi9m", | ||
rank: "ADMIN", | ||
type: "ADMIN", | ||
apikey: "Gssy-ffy.okeTA-3AJhCnY1sqeUvRPRHiNYIVUxs4", | ||
}; | ||
|
||
const seed = async (pool) => { | ||
const newUser = await pool.query( | ||
`SELECT userid, verifyid FROM thunderdome.user_register($1, $2, $3, $4);`, | ||
[ | ||
adminAPIUser.name, | ||
adminAPIUser.email, | ||
adminAPIUser.hashedPass, | ||
adminAPIUser.rank, | ||
], | ||
const seeder = new ThunderdomeSeeder(pool); | ||
const { id } = await seeder.createUser( | ||
adminAPIUser.name, | ||
adminAPIUser.email, | ||
adminAPIUser.type, | ||
true, | ||
); | ||
const id = newUser.rows[0].userid; | ||
|
||
await pool.query("call thunderdome.user_account_verify($1);", [ | ||
newUser.rows[0].verifyid, | ||
]); | ||
|
||
await pool.query( | ||
`INSERT INTO thunderdome.api_key (id, user_id, name, active) VALUES ($1, $2, $3, TRUE);`, | ||
[ | ||
"Gssy-ffy.e170ffced2ae5806aebc103f30255dc5cc1b9e203d6035aa817f2b7e6638f223", | ||
id, | ||
"test api key 2", | ||
], | ||
await seeder.addUserAPIKey( | ||
id, | ||
"Gssy-ffy.e170ffced2ae5806aebc103f30255dc5cc1b9e203d6035aa817f2b7e6638f223", | ||
"test api key 2", | ||
); | ||
|
||
return { | ||
|
@@ -39,16 +29,8 @@ const seed = async (pool) => { | |
}; | ||
|
||
const teardown = async (pool) => { | ||
const oldUser = await pool.query( | ||
`SELECT id FROM thunderdome.users WHERE email = $1;`, | ||
[adminAPIUser.email], | ||
); | ||
|
||
if (oldUser.rows.length) { | ||
await pool.query("DELETE FROM thunderdome.users WHERE id = $1;", [ | ||
oldUser.rows[0].id, | ||
]); | ||
} | ||
const seeder = new ThunderdomeSeeder(pool); | ||
await seeder.deleteUserByEmail(adminAPIUser.email); | ||
|
||
return {}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import { ThunderdomeSeeder } from "./seeder"; | ||
|
||
export const apiUser = { | ||
name: "E2E API User", | ||
name: "E2EAPIUser", | ||
email: "[email protected]", | ||
password: "kentRules!", | ||
hashedPass: "$2a$10$3CvuzyoGIme3dJ4v9BnvyOIKFxEaYyjV2Lfunykv0VokGf/twxi9m", | ||
rank: "REGISTERED", | ||
type: "REGISTERED", | ||
apikey: "8MenPkY8.Vqvkh030vv7$rSyYs1gt++L0v7wKuVgR", | ||
}; | ||
|
||
const seed = async (pool) => { | ||
const newUser = await pool.query( | ||
`SELECT userid, verifyid FROM thunderdome.user_register($1, $2, $3, $4);`, | ||
[apiUser.name, apiUser.email, apiUser.hashedPass, apiUser.rank], | ||
const seeder = new ThunderdomeSeeder(pool); | ||
const { id } = await seeder.createUser( | ||
apiUser.name, | ||
apiUser.email, | ||
apiUser.type, | ||
true, | ||
); | ||
const id = newUser.rows[0].userid; | ||
|
||
await pool.query("call thunderdome.user_account_verify($1);", [ | ||
newUser.rows[0].verifyid, | ||
]); | ||
|
||
await pool.query( | ||
`INSERT INTO thunderdome.api_key (id, user_id, name, active) VALUES ($1, $2, $3, TRUE);`, | ||
[ | ||
"8MenPkY8.cd737cbc4bdca1838bdcf1685b00a9a778261255c10193714d9ba1630b55b63c", | ||
id, | ||
"test apikey", | ||
], | ||
await seeder.addUserAPIKey( | ||
id, | ||
"8MenPkY8.cd737cbc4bdca1838bdcf1685b00a9a778261255c10193714d9ba1630b55b63c", | ||
"test apikey", | ||
); | ||
|
||
return { | ||
|
@@ -34,16 +29,8 @@ const seed = async (pool) => { | |
}; | ||
|
||
const teardown = async (pool) => { | ||
const oldUser = await pool.query( | ||
`SELECT id FROM thunderdome.users WHERE email = $1;`, | ||
[apiUser.email], | ||
); | ||
|
||
if (oldUser.rows.length) { | ||
await pool.query("DELETE FROM thunderdome.users WHERE id = $1;", [ | ||
oldUser.rows[0].id, | ||
]); | ||
} | ||
const seeder = new ThunderdomeSeeder(pool); | ||
await seeder.deleteUserByEmail(apiUser.email); | ||
|
||
return {}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
import { ThunderdomeSeeder } from "./seeder"; | ||
|
||
export const registeredDeleteUser = { | ||
name: "E2E Delete User", | ||
email: "[email protected]", | ||
password: "kentRules!", | ||
hashedPass: "$2a$10$3CvuzyoGIme3dJ4v9BnvyOIKFxEaYyjV2Lfunykv0VokGf/twxi9m", | ||
rank: "REGISTERED", | ||
type: "REGISTERED", | ||
}; | ||
|
||
const seed = async (pool) => { | ||
const newUser = await pool.query( | ||
`SELECT userid, verifyid FROM thunderdome.user_register($1, $2, $3, $4);`, | ||
[ | ||
registeredDeleteUser.name, | ||
registeredDeleteUser.email, | ||
registeredDeleteUser.hashedPass, | ||
registeredDeleteUser.rank, | ||
], | ||
const seeder = new ThunderdomeSeeder(pool); | ||
const { id } = await seeder.createUser( | ||
registeredDeleteUser.name, | ||
registeredDeleteUser.email, | ||
registeredDeleteUser.type, | ||
false, | ||
); | ||
const id = newUser.rows[0].userid; | ||
|
||
return { | ||
...registeredDeleteUser, | ||
|
@@ -25,16 +22,8 @@ const seed = async (pool) => { | |
}; | ||
|
||
const teardown = async (pool) => { | ||
const oldUser = await pool.query( | ||
`SELECT id FROM thunderdome.users WHERE email = $1;`, | ||
[registeredDeleteUser.email], | ||
); | ||
|
||
if (oldUser.rows.length) { | ||
await pool.query("DELETE FROM thunderdome.users WHERE id = $1;", [ | ||
oldUser.rows[0].id, | ||
]); | ||
} | ||
const seeder = new ThunderdomeSeeder(pool); | ||
await seeder.deleteUserByEmail(registeredDeleteUser.email); | ||
|
||
return {}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
import { ThunderdomeSeeder } from "./seeder"; | ||
|
||
export const registeredUser = { | ||
name: "E2E Registered User", | ||
email: "[email protected]", | ||
password: "kentRules!", | ||
hashedPass: "$2a$10$3CvuzyoGIme3dJ4v9BnvyOIKFxEaYyjV2Lfunykv0VokGf/twxi9m", | ||
rank: "REGISTERED", | ||
type: "REGISTERED", | ||
}; | ||
|
||
const seed = async (pool) => { | ||
const newUser = await pool.query( | ||
`SELECT userid, verifyid FROM thunderdome.user_register($1, $2, $3, $4);`, | ||
[ | ||
registeredUser.name, | ||
registeredUser.email, | ||
registeredUser.hashedPass, | ||
registeredUser.rank, | ||
], | ||
const seeder = new ThunderdomeSeeder(pool); | ||
const { id } = await seeder.createUser( | ||
registeredUser.name, | ||
registeredUser.email, | ||
registeredUser.type, | ||
false, | ||
); | ||
const id = newUser.rows[0].userid; | ||
|
||
return { | ||
...registeredUser, | ||
|
@@ -25,16 +22,8 @@ const seed = async (pool) => { | |
}; | ||
|
||
const teardown = async (pool) => { | ||
const oldUser = await pool.query( | ||
`SELECT id FROM thunderdome.users WHERE email = $1;`, | ||
[registeredUser.email], | ||
); | ||
|
||
if (oldUser.rows.length) { | ||
await pool.query("DELETE FROM thunderdome.users WHERE id = $1;", [ | ||
oldUser.rows[0].id, | ||
]); | ||
} | ||
const seeder = new ThunderdomeSeeder(pool); | ||
await seeder.deleteUserByEmail(registeredUser.email); | ||
|
||
return {}; | ||
}; | ||
|
Oops, something went wrong.