Skip to content

Commit

Permalink
add account name length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
olaszakos committed Nov 18, 2024
1 parent 90f13c6 commit fd27a4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
:disabled="isViewMode || !!model.id"
:multiple="true"
/>
<!-- @selected-asset="onSelectedAsset" -->
</VCol>
<VCol cols="12" class="pt-0 pb-4">
<VTextField
v-model="model.name"
name="name"
:label="$t('terms.name')"
:rules="[requiredRule]"
:rules="[requiredRule, maxLengthRule(64, $t('terms.name'))]"
variant="filled"
class="mb-2"
density="comfortable"
Expand All @@ -49,7 +48,7 @@ import { computed } from 'vue';
import { VCol, VRow, VTextField } from 'vuetify/components';
import TokenAutocomplete from '~/components/inputs/TokenAutocomplete.vue';
import { TimestampRFC3339, UUID } from '~/generated/station/station.did';
import { requiredRule } from '~/utils/form.utils';
import { maxLengthRule, requiredRule } from '~/utils/form.utils';
export interface AccountConfigurationModel {
id: UUID;
Expand Down
5 changes: 5 additions & 0 deletions core/station/impl/src/errors/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub enum AccountError {
r#"The account address is out of range, it must be between {min_length} and {max_length}."#
)]
InvalidAddressLength { min_length: u8, max_length: u8 },
/// The account name is out of range.
#[error(
r#"The account name is out of range, it must be between {min_length} and {max_length}."#
)]
InvalidNameLength { min_length: u8, max_length: u8 },
/// The address format is unknown to the system.
#[error(r#"The given address format is unknown to the system."#)]
UnknownAddressFormat { address_format: String },
Expand Down
16 changes: 16 additions & 0 deletions core/station/impl/src/models/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,25 @@ fn validate_asset_id(asset_id: &AssetId) -> ModelValidatorResult<AccountError> {
Ok(())
}

fn validate_account_name(name: &str) -> ModelValidatorResult<AccountError> {
if (name.len() < Account::NAME_RANGE.0 as usize)
|| (name.len() > Account::NAME_RANGE.1 as usize)
{
return Err(AccountError::InvalidNameLength {
min_length: Account::NAME_RANGE.0,
max_length: Account::NAME_RANGE.1,
});
}

Ok(())
}

impl ModelValidator<AccountError> for Account {
fn validate(&self) -> ModelValidatorResult<AccountError> {
self.metadata.validate()?;

validate_account_name(&self.name)?;

for asset in &self.assets {
validate_asset_id(&asset.asset_id)?;
}
Expand All @@ -216,6 +231,7 @@ impl ModelValidator<AccountError> for Account {
impl Account {
pub const OWNERS_RANGE: (u8, u8) = (1, 10);
pub const ADDRESS_RANGE: (u8, u8) = (1, 255);
pub const NAME_RANGE: (u8, u8) = (1, 64);
pub const SYMBOL_RANGE: (u8, u8) = (1, 8);
pub const MAX_POLICIES: u8 = 10;

Expand Down

0 comments on commit fd27a4f

Please sign in to comment.