Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webserver): validation should always comes with message field #1981

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +18,10 @@ 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,
}
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
Loading