Skip to content

Commit

Permalink
fix: failles securité yeswehack
Browse files Browse the repository at this point in the history
  • Loading branch information
remy-auricoste committed Dec 14, 2023
1 parent 6820de9 commit eb1fd5b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion server/src/security/authorisationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ export function isAuthorized(access: AccessPermission, userWithType: NonTokenUse

switch (access) {
case "recruiter:manage":
case "recruiter:validate":
case "recruiter:add_job":
return resources.recruiters.every((recruiter) => canAccessRecruiter(userWithType, recruiter))

Expand All @@ -325,6 +324,7 @@ export function isAuthorized(access: AccessPermission, userWithType: NonTokenUse
return resources.users.every((user) => canAccessUser(userWithType, user))
case "application:manage":
return resources.applications.every((application) => canAccessApplication(userWithType, application))
case "user:validate":
case "user:manage":
return resources.users.every((user) => canAccessUser(userWithType, user))
case "admin":
Expand Down
22 changes: 11 additions & 11 deletions server/tests/unit/security/authorisationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe("authorisationService", () => {
describe("as an admin user", () => {
describe.each<[Permission]>([
["recruiter:manage"],
["recruiter:validate"],
["user:validate"],
["recruiter:add_job"],
["job:manage"],
["school:manage"],
Expand Down Expand Up @@ -391,7 +391,7 @@ describe("authorisationService", () => {
})

describe("as an opco user", () => {
describe.each<[Permission]>([["recruiter:manage"], ["recruiter:validate"], ["recruiter:add_job"]])("I have %s permission", (permission) => {
describe.each<[Permission]>([["recruiter:manage"], ["user:validate"], ["recruiter:add_job"]])("I have %s permission", (permission) => {
it("on all recruiters from my opco", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO1E1R1, recruteurO1E1R2, recruteurO1E2R1], location)
await expect(
Expand Down Expand Up @@ -476,7 +476,7 @@ describe("authorisationService", () => {
})
})

describe.each<[Permission]>([["recruiter:manage"], ["recruiter:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
describe.each<[Permission]>([["recruiter:manage"], ["user:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
it("on recruiter from other Opco", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO2E1R1], location)
await expect(
Expand Down Expand Up @@ -653,7 +653,7 @@ describe("authorisationService", () => {
})

describe("as an opco credential", () => {
describe.each<[Permission]>([["recruiter:manage"], ["recruiter:validate"], ["recruiter:add_job"]])("I have %s permission", (permission) => {
describe.each<[Permission]>([["recruiter:manage"], ["user:validate"], ["recruiter:add_job"]])("I have %s permission", (permission) => {
it("on all recruiters from my opco", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO1E1R1, recruteurO1E1R2, recruteurO1E2R1], location)
await expect(
Expand Down Expand Up @@ -717,7 +717,7 @@ describe("authorisationService", () => {
})
})

describe.each<[Permission]>([["recruiter:manage"], ["recruiter:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
describe.each<[Permission]>([["recruiter:manage"], ["user:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
it("on recruiter from other Opco", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO2E1R1], location)
await expect(
Expand Down Expand Up @@ -980,7 +980,7 @@ describe("authorisationService", () => {
})
})

describe.each<[Permission]>([["recruiter:validate"]])("I do not have %s permission", (permission) => {
describe.each<[Permission]>([["user:validate"]])("I do not have %s permission", (permission) => {
it("on all my delegated recruiters", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO1E1R1], location)
await expect(
Expand All @@ -1002,7 +1002,7 @@ describe("authorisationService", () => {
})
})

describe.each<[Permission]>([["recruiter:manage"], ["recruiter:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
describe.each<[Permission]>([["recruiter:manage"], ["user:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
it("on non delegated recruiters", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO1E1R2], location)
await expect(
Expand Down Expand Up @@ -1242,7 +1242,7 @@ describe("authorisationService", () => {
})
})

describe.each<[Permission]>([["recruiter:validate"]])("I do not have %s permission", (permission) => {
describe.each<[Permission]>([["user:validate"]])("I do not have %s permission", (permission) => {
it("on me", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO1E1R1], location)
await expect(
Expand All @@ -1264,7 +1264,7 @@ describe("authorisationService", () => {
})
})

describe.each<[Permission]>([["recruiter:manage"], ["recruiter:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
describe.each<[Permission]>([["recruiter:manage"], ["user:validate"], ["recruiter:add_job"], ["admin"]])("I do not have %s permission", (permission) => {
it("on other recruiters from my company", async () => {
const [securityScheme, req] = generateSecuritySchemeFixture(permission, [recruteurO1E1R2], location)
await expect(
Expand Down Expand Up @@ -1479,7 +1479,7 @@ describe("authorisationService", () => {
it("should support some operator permission", async () => {
const securityScheme: SecurityScheme = {
auth: "cookie-session",
access: { some: ["recruiter:manage", "recruiter:validate"] },
access: { some: ["recruiter:manage", "user:validate"] },
resources: {
recruiter: [
{
Expand Down Expand Up @@ -1535,7 +1535,7 @@ describe("authorisationService", () => {
it("should support every operator permission", async () => {
const securityScheme: SecurityScheme = {
auth: "cookie-session",
access: { every: ["recruiter:manage", "recruiter:validate"] },
access: { every: ["recruiter:manage", "user:validate"] },
resources: {
recruiter: [
{
Expand Down
2 changes: 1 addition & 1 deletion shared/routes/recruiters.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const zRecruiterRoutes = {
},
securityScheme: {
auth: "cookie-session",
access: null,
access: "user:manage",
resources: {
user: [{ _id: { type: "params", key: "id" } }],
},
Expand Down
2 changes: 1 addition & 1 deletion shared/routes/user.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const zUserRecruteurRoutes = {
},
securityScheme: {
auth: "cookie-session",
access: "user:manage",
access: "user:validate",
resources: {
user: [{ _id: { type: "params", key: "userId" } }],
},
Expand Down
2 changes: 1 addition & 1 deletion shared/routes/v1Jobs.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export const zV1JobsRoutes = {
},
securityScheme: {
auth: "api-key",
access: { every: ["recruiter:validate", "recruiter:manage"] },
access: { every: ["user:validate", "recruiter:manage", "user:manage"] },
resources: {},
},
openapi: {
Expand Down
4 changes: 2 additions & 2 deletions shared/security/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Permission = "recruiter:manage" | "recruiter:validate" | "recruiter:add_job" | "job:manage" | "school:manage" | "application:manage" | "user:manage" | "admin"
export type Permission = "recruiter:manage" | "user:validate" | "recruiter:add_job" | "job:manage" | "school:manage" | "application:manage" | "user:manage" | "admin"

export type RoleNames = "opco" | "recruiter" | "cfa" | "admin"

Expand All @@ -9,7 +9,7 @@ export interface Role {

export const OpcoRole = {
name: "opco",
permissions: ["recruiter:manage", "recruiter:validate", "recruiter:add_job", "job:manage", "user:manage"],
permissions: ["recruiter:manage", "user:validate", "recruiter:add_job", "job:manage", "user:manage"],
} satisfies Role

export const RecruiterRole = {
Expand Down

0 comments on commit eb1fd5b

Please sign in to comment.