Skip to content

Commit

Permalink
fix(webserver): validation should always comes with message field (#1981
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wsxiaoys authored Apr 26, 2024
1 parent cb9a8a7 commit f0632e6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ impl relay::NodeType for User {

#[derive(Validate, GraphQLInputObject)]
pub struct RequestInvitationInput {
#[validate(email(code = "email"))]
#[validate(email(code = "email", message = "Invalid email address"))]
pub email: String,
}

#[derive(Validate, GraphQLInputObject)]
pub struct RequestPasswordResetEmailInput {
#[validate(email(code = "email"))]
#[validate(email(code = "email", message = "Invalid email address"))]
pub email: String,
}

Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/schema/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use lazy_static::lazy_static;
use regex::Regex;

lazy_static! {
pub static ref REPOSITORY_NAME_REGEX: Regex = Regex::new("^[\\w-]+$").unwrap();
pub static ref REPOSITORY_NAME_REGEX: Regex = Regex::new("^[a-zA-Z][\\w.-]+$").unwrap();
}
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/schema/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct EmailSetting {
#[derive(GraphQLInputObject, Validate)]
pub struct EmailSettingInput {
pub smtp_username: String,
#[validate(email(code = "fromAddress"))]
#[validate(email(code = "fromAddress", message = "Invalid email address"))]
pub from_address: String,
pub smtp_server: String,
pub smtp_port: i32,
Expand Down
10 changes: 6 additions & 4 deletions ee/tabby-webserver/src/schema/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use validator::Validate;
pub struct CreateRepositoryProviderInput {
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
path = "crate::schema::constants::REPOSITORY_NAME_REGEX",
message = "Invalid repository provider name"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
#[validate(length(code = "accessToken", min = 10, message = "Invalid access token"))]
pub access_token: String,
}

Expand All @@ -17,10 +18,11 @@ pub struct UpdateRepositoryProviderInput {
pub id: ID,
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
path = "crate::schema::constants::REPOSITORY_NAME_REGEX",
message = "Invalid repository provider name"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
#[validate(length(code = "accessToken", min = 10, message = "Invalid access token"))]
pub access_token: String,
}

Expand Down
18 changes: 11 additions & 7 deletions rules/validate-requires-code.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
id: validate-requires-code
message: Validations requires code being set for frontend error display
message: Validations requires code / message being set for frontend error display
severity: error
language: rust
files:
- ./ee/tabby-webserver/src/**
- ./ee/tabby-webserver/src/**
rule:
all:
- pattern: '#[validate]'
- pattern: "#[validate]"
- not:
has:
stopBy: end
pattern: code
all:
- has:
stopBy: end
pattern: code
- has:
stopBy: end
pattern: message
- not:
has:
stopBy: end
pattern: custom
pattern: custom

0 comments on commit f0632e6

Please sign in to comment.