-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Restrict certain users from production environments (#2530)
* chore: Add is_staging_only column to users table * chore: Update sync script * feat: Check if user can access env * fix: Typo in migration, comment out sync script * chore: Bump planx-new
- Loading branch information
1 parent
5131700
commit 1c3fc32
Showing
13 changed files
with
231 additions
and
132 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { checkUserCanAccessEnv } from "./service"; | ||
|
||
const mockIsStagingOnly = jest.fn(); | ||
|
||
jest.mock("../../client", () => { | ||
return { | ||
$api: { | ||
user: { | ||
isStagingOnly: () => mockIsStagingOnly(), | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe("canUserAccessEnv() helper function", () => { | ||
describe("a staging-only user", () => { | ||
beforeAll(() => mockIsStagingOnly.mockResolvedValue(true)); | ||
|
||
test("can't access production", async () => { | ||
const result = await checkUserCanAccessEnv( | ||
"[email protected]", | ||
"production", | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
test("can access staging", async () => { | ||
const result = await checkUserCanAccessEnv("[email protected]", "staging"); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("can access pizzas", async () => { | ||
const result = await checkUserCanAccessEnv("[email protected]", "pizza"); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("can access test envs", async () => { | ||
const result = await checkUserCanAccessEnv("[email protected]", "test"); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe("a non staging-only user", () => { | ||
beforeAll(() => mockIsStagingOnly.mockResolvedValue(false)); | ||
|
||
test("can access production", async () => { | ||
const result = await checkUserCanAccessEnv( | ||
"[email protected]", | ||
"production", | ||
); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("can access staging", async () => { | ||
const result = await checkUserCanAccessEnv("[email protected]", "staging"); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("can access pizzas", async () => { | ||
const result = await checkUserCanAccessEnv("[email protected]", "pizza"); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("can access test envs", async () => { | ||
const result = await checkUserCanAccessEnv("[email protected]", "test"); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.