Skip to content

Commit

Permalink
fix(tests): fix issues with user not being recognized as coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jul 7, 2023
1 parent 9346a6f commit 14a6ecd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/actions/test/unit/security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ describe("Security", () => {
await expect(createS3Bucket(userFunctions, "prefix")).to.be.rejectedWith(
"You do not have privileges to perform this operation."
)
await signOut(userAuth)
})
it("should html encode malicious characters passed as part of a ceremony creation data", async () => {
const ceremonyData = {
Expand All @@ -580,6 +581,7 @@ describe("Security", () => {

const ceremonyBucket = getBucketName(ceremonyData.prefix, ceremonyBucketPostfix)
await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2])
await sleep(1000)
const currentUser = getCurrentFirebaseAuthUser(userApp)
expect(await isCoordinator(currentUser)).to.be.true
const ceremonyId = await setupCeremony(userFunctions, ceremonyData, ceremonyBucket, [circuitData])
Expand Down
10 changes: 5 additions & 5 deletions packages/actions/test/utils/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createOAuthDeviceAuth } from "@octokit/auth-oauth-device"
import { createUserWithEmailAndPassword, getAuth, GithubAuthProvider, UserCredential } from "firebase/auth"
import { FirebaseApp } from "firebase/app"
import { Auth } from "firebase-admin/auth"
import { getCurrentFirebaseAuthUser, signInToFirebaseWithCredentials } from "../../src/index"
import { getCurrentFirebaseAuthUser, isCoordinator, signInToFirebaseWithCredentials } from "../../src/index"
import { getAuthenticationConfiguration } from "./configs"
import { UserDocumentReferenceAndData } from "../../src/types/index"

Expand Down Expand Up @@ -536,14 +536,14 @@ export const setCustomClaims = async (
* @param userApp <FirebaseApp> - the Firebase user Application instance.
* @param email <string> - the email of the user.
* @param password <string> - the password of the user.
* @param isCoordinator <boolean> - whether the user is a coordinator or not.
* @param isUserCoordinator <boolean> - whether the user is a coordinator or not.
* @param adminAuth <Auth> - the admin auth instance.
*/
export const createMockUser = async (
userApp: FirebaseApp,
email: string,
password: string,
isCoordinator: boolean = true,
isUserCoordinator: boolean = true,
adminAuth?: Auth
): Promise<string> => {
await createNewFirebaseUserWithEmailAndPw(userApp, email, password)
Expand All @@ -553,10 +553,10 @@ export const createMockUser = async (
const currentAuthenticatedUser = getCurrentFirebaseAuthUser(userApp)
const uid = currentAuthenticatedUser?.uid

if (isCoordinator) {
if (isUserCoordinator) {
if (!adminAuth) throw new Error("Admin auth instance is required to set a user as coordinator.")
await setCustomClaims(adminAuth, uid, { coordinator: true })
await sleep(1000)
await sleep(2000)
}

return uid
Expand Down

0 comments on commit 14a6ecd

Please sign in to comment.