Skip to content

Commit

Permalink
fix group name verification
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Mar 9, 2020
1 parent d36dce3 commit 5a2bf5c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ci/install_deps.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export RUSTUP_HOME=/usr/local/rustup
export CARGO_HOME=/usr/local/cargo
export PATH=/usr/local/cargo/bin:$PATH
export RUST_VERSION=1.40.0
export RUST_VERSION=1.41.1

set -eux

Expand Down
4 changes: 2 additions & 2 deletions src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::fmt::Display;

#[derive(Fail, Debug)]
pub enum ApiError {
#[fail(display = "A mulipart error occured.")]
#[fail(display = "A multipart error occurred.")]
MultipartError,
#[fail(display = "Bad API request.")]
GenericBadRequest(failure::Error),
#[fail(display = "Group names must ony containe alphanumeric charactars, -, and _")]
#[fail(display = "Group names must ony contain lowercase alphanumeric characters, -, and _")]
InvalidGroupName,
#[fail(display = "Operation Error: {}", _0)]
PacksError(PacksError),
Expand Down
1 change: 0 additions & 1 deletion src/rules/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::db::types::*;
use crate::rules::error::RuleError;
use crate::rules::RuleContext;
use crate::utils::valid_group_name;
use diesel::result::Error as DieselError;
use dino_park_trust::GroupsTrust;
use dino_park_trust::Trust;

Expand Down
9 changes: 8 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn to_expiration_ts(days: i32) -> NaiveDateTime {
pub fn valid_group_name(group_name: &str) -> bool {
group_name
.chars()
.all(|c| c.is_ascii_alphanumeric() && c.is_lowercase() || c == '-' || c == '_')
.all(|c| (c.is_ascii_lowercase() || c.is_ascii_digit()) || c == '-' || c == '_')
}

pub fn maybe_to_utc<S>(naive: &Option<NaiveDateTime>, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -38,6 +38,13 @@ mod test {
use failure::Error;
use serde_json;

#[test]
fn test_group_names() {
assert!(valid_group_name("group-test-1"));
assert!(!valid_group_name("group-Test-1"));
assert!(!valid_group_name("group-Test.1"));
}

#[test]
fn test_to_utc() -> Result<(), Error> {
#[derive(Serialize)]
Expand Down

0 comments on commit 5a2bf5c

Please sign in to comment.