Skip to content

Commit

Permalink
fix(auth tests): implemented changes after PR review
Browse files Browse the repository at this point in the history
Implemented changes on Auth tests after PR review. This includes removing the export of unused
functions, and adding more thorough comments in the code.
  • Loading branch information
ctrlc03 committed Jan 26, 2023
1 parent 2b48897 commit 5d16838
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
5 changes: 4 additions & 1 deletion packages/actions/test/e2e/00-authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe("Authentication", () => {
expect(currentAuthenticatedUser.emailVerified).to.be.equal(user.data.emailVerified)
expect(currentAuthenticatedUser.emailVerified).to.be.equal(data?.emailVerified)
expect(currentAuthenticatedUser.displayName).to.be.null // due to mail/pw provider.
// expect(currentAuthenticatedUser.displayName).to.be.equal(data?.displayName)
expect(currentAuthenticatedUser.photoURL).to.be.null // due to mail/pw provider.
expect(data?.photoURL).to.be.empty // due to mail/pw provider.
expect(new Date(String(currentAuthenticatedUser.metadata.creationTime)).valueOf()).to.be.equal(
Expand All @@ -67,6 +66,7 @@ describe("Authentication", () => {
const disabledRecord = await adminAuth.updateUser(user.uid, { disabled: true })
expect(disabledRecord.disabled).to.be.true

// Try to authenticate with the disabled user.
await expect(signInWithEmailAndPassword(userAuth, user.data.email, userPassword)).to.be.rejectedWith(
"Firebase: Error (auth/user-disabled)."
)
Expand All @@ -79,18 +79,21 @@ describe("Authentication", () => {
})

it("should not be possible to authenticate with an incorrect password", async () => {
// Try to authenticate with the wrong password.
await expect(signInWithEmailAndPassword(userAuth, user.data.email, "wrongPassword")).to.be.rejectedWith(
"Firebase: Error (auth/wrong-password)."
)
})

it("should not be possible to authenticate with an incorrect email", async () => {
// Try to authenticate with the wrong email.
await expect(signInWithEmailAndPassword(userAuth, "wrongEmail", userPassword)).to.be.rejected
})

it("should not be possible to authenticate if Firebase is unreachable", async () => {
// @todo mock unreachable firebase.
})

it("should not be possible to authenticate twice", async () => {
// @todo Implement checks to prevent double authentication.
})
Expand Down
10 changes: 6 additions & 4 deletions packages/actions/test/utils/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const createNewFirebaseUserWithEmailAndPw = async (
* @param gmailRefreshToken <string> - the GMail refresh token.
* @dev You should have the GMail APIs for OAuth2.0 must be enabled and configured properly in order to get correct results.
* @returns <Promise<string>> - return the 6 digits verification code needed to complete the access with Github.
* @todo this method will not be used for testing right now. See PR #286 and #289 for info.
*/
export const getLastGithubVerificationCode = async (
gmailUserEmail: string,
Expand Down Expand Up @@ -78,9 +79,9 @@ export const getLastGithubVerificationCode = async (
/**
* Simulate callback to manage the data requested for Github OAuth2.0 device flow.
* @param verification <Verification> - the data from Github OAuth2.0 device flow.
* @todo this method will not be used for testing right now. See PR #286 and #289 for info.
*/
export const simulateOnVerification = async (verification: Verification): Promise<any> => {
// NB. this method will not be used for testing right now. See PR #286 for info.
// 0.A Prepare data and plugins.
const { userEmail, githubUserPw, gmailClientId, gmailClientSecret, gmailRedirectUrl, gmailRefreshToken } =
getAuthenticationConfiguration()
Expand Down Expand Up @@ -198,9 +199,9 @@ export const simulateOnVerification = async (verification: Verification): Promis
/**
* Simulate callback to cancel authorization for Github OAuth2.0 device flow.
* @param verification <Verification> - the data from Github OAuth2.0 device flow.
* @todo this method will not be used for testing right now. See PR #286 and #289 for info.
*/
export const simulateCancelledOnVerification = async (verification: Verification): Promise<any> => {
// NB. this method will not be used for testing right now. See PR #286 for info.
// 0.A Prepare data and plugins.
const { userEmail, githubUserPw, gmailClientId, gmailClientSecret, gmailRedirectUrl, gmailRefreshToken } =
getAuthenticationConfiguration()
Expand Down Expand Up @@ -311,9 +312,9 @@ export const simulateCancelledOnVerification = async (verification: Verification
/**
* Simulate callback sending an invalid device code for Github OAuth2.0 device flow.
* @param verification <Verification> - the data from Github OAuth2.0 device flow.
* @todo this method will not be used for testing right now. See PR #286 and #289 for info.
*/
export const simulateInvalidTokenOnVerification = async (verification: Verification): Promise<any> => {
// NB. this method will not be used for testing right now. See PR #286 for info.
// 0.A Prepare data and plugins.
const { userEmail, githubUserPw, gmailClientId, gmailClientSecret, gmailRedirectUrl, gmailRefreshToken } =
getAuthenticationConfiguration()
Expand Down Expand Up @@ -418,10 +419,10 @@ export const simulateInvalidTokenOnVerification = async (verification: Verificat
/**
* Simulate callback for unreachable GitHub website for Github OAuth2.0 device flow.
* @param verification <Verification> - the data from Github OAuth2.0 device flow.
* @todo this method will not be used for testing right now. See PR #286 and #289 for info.
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
export const simulateUnreachablePageOnVerification = async (verification: Verification): Promise<any> => {
// NB. this method will not be used for testing right now. See PR #286 for info.
puppeteerExtra.use(stealthMode())
puppeteerExtra.use(anonUserAgent({ stripHeadless: true }))

Expand Down Expand Up @@ -474,6 +475,7 @@ export const simulateUnreachablePageOnVerification = async (verification: Verifi
* @param userApp <FirebaseApp> - the Firebase user Application instance.
* @param clientId <string> - the Github client id.
* @returns <Promise<UserCredential>> - the credential of the user after the handshake with Firebase.
* @todo this method will not be used for testing right now. See PR #286 and #289 for info.
*/
export const authenticateUserWithGithub = async (userApp: FirebaseApp, clientId: string): Promise<UserCredential> => {
const clientType = "oauth-app"
Expand Down
10 changes: 1 addition & 9 deletions packages/actions/test/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@ export {
generatePseudoRandomStringOfNumbers
} from "./configs"

export {
createNewFirebaseUserWithEmailAndPw,
getLastGithubVerificationCode,
simulateOnVerification,
authenticateUserWithGithub,
simulateCancelledOnVerification,
simulateUnreachablePageOnVerification,
simulateInvalidTokenOnVerification
} from "./authentication"
export { createNewFirebaseUserWithEmailAndPw } from "./authentication"

0 comments on commit 5d16838

Please sign in to comment.