Skip to content

Commit

Permalink
Deprecates numbers and renames it to digits
Browse files Browse the repository at this point in the history
  • Loading branch information
ogarcia committed Jan 18, 2025
1 parent dfb33d5 commit 300e246
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rockpass"
version = "0.9.0"
version = "0.10.0"
authors = ["Óscar García Amor"]
license = "GPL-3.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ Login: [email protected]
Lowercase: true
Uppercase: true
Symbols: true
Numbers: true
Digits: true
Length: 16
Couter: 1

Expand Down
36 changes: 36 additions & 0 deletions migrations/2025-01-18-102431_digits/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP INDEX IF EXISTS passwords_unique;

CREATE TABLE IF NOT EXISTS passwords_migration (
id INTEGER NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
login TEXT NOT NULL,
site TEXT NOT NULL,
uppercase BOOLEAN NOT NULL DEFAULT TRUE,
symbols BOOLEAN NOT NULL DEFAULT TRUE,
lowercase BOOLEAN NOT NULL DEFAULT TRUE,
numbers BOOLEAN NOT NULL DEFAULT TRUE,
counter INTEGER NOT NULL DEFAULT 1,
version INTEGER NOT NULL DEFAULT 2,
length INTEGER NOT NULL DEFAULT 16,
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO passwords_migration (
id,
user_id,
login,
site,
uppercase,
symbols,
lowercase,
numbers,
counter,
version,
length,
created,
modified
) SELECT id, user_id, login, site, uppercase, symbols, lowercase, digits, counter, version, length, created, modified FROM passwords;
DROP TABLE passwords;
ALTER TABLE passwords_migration RENAME TO passwords;

CREATE UNIQUE INDEX IF NOT EXISTS passwords_unique ON passwords (user_id, login, site);
36 changes: 36 additions & 0 deletions migrations/2025-01-18-102431_digits/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP INDEX IF EXISTS passwords_unique;

CREATE TABLE IF NOT EXISTS passwords_migration (
id INTEGER NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
login TEXT NOT NULL,
site TEXT NOT NULL,
uppercase BOOLEAN NOT NULL DEFAULT TRUE,
symbols BOOLEAN NOT NULL DEFAULT TRUE,
lowercase BOOLEAN NOT NULL DEFAULT TRUE,
digits BOOLEAN NOT NULL DEFAULT TRUE,
counter INTEGER NOT NULL DEFAULT 1,
version INTEGER NOT NULL DEFAULT 2,
length INTEGER NOT NULL DEFAULT 16,
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO passwords_migration (
id,
user_id,
login,
site,
uppercase,
symbols,
lowercase,
digits,
counter,
version,
length,
created,
modified
) SELECT id, user_id, login, site, uppercase, symbols, lowercase, numbers, counter, version, length, created, modified FROM passwords;
DROP TABLE passwords;
ALTER TABLE passwords_migration RENAME TO passwords;

CREATE UNIQUE INDEX IF NOT EXISTS passwords_unique ON passwords (user_id, login, site);
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ mod tests {
client.post("/passwords")
.header(ContentType::JSON)
.header(Header::new("authorization", format!("bearer {}", token.access)))
.body(r#"{"login":"[email protected]","site":"rockpass.sample","uppercase":true,"symbols":true,"lowercase":true,"numbers":true,"counter":1,"version":2,"length":16}"#)
.body(r#"{"login":"[email protected]","site":"rockpass.sample","uppercase":true,"symbols":true,"lowercase":true,"digits":true,"counter":1,"version":2,"length":16}"#)
.dispatch().await;
client.post("/passwords")
.header(ContentType::JSON)
.header(Header::new("authorization", format!("bearer {}", token.access)))
.body(r#"{"login":"[email protected]","site":"subsite.rockpass.sample","uppercase":true,"symbols":false,"lowercase":true,"numbers":true,"counter":2,"version":2,"length":16}"#)
.body(r#"{"login":"[email protected]","site":"subsite.rockpass.sample","uppercase":true,"symbols":false,"lowercase":true,"digits":true,"counter":2,"version":2,"length":16}"#)
.dispatch().await;
client.post("/passwords")
.header(ContentType::JSON)
.header(Header::new("authorization", format!("bearer {}", token.access)))
.body(r#"{"login":"[email protected]","site":"other.rockpass.sample","uppercase":true,"symbols":false,"lowercase":true,"numbers":false,"counter":1,"version":2,"length":8}"#)
.body(r#"{"login":"[email protected]","site":"other.rockpass.sample","uppercase":true,"symbols":false,"lowercase":true,"digits":false,"counter":1,"version":2,"length":8}"#)
.dispatch().await;
}

Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
let request = client.put("/passwords/100")
.header(ContentType::JSON)
.header(Header::new("authorization", format!("bearer {}", token.access)))
.body(r#"{"login":"[email protected]","site":"rockpass.sample","uppercase":true,"symbols":true,"lowercase":true,"numbers":true,"counter":1,"version":2,"length":16}"#);
.body(r#"{"login":"[email protected]","site":"rockpass.sample","uppercase":true,"symbols":true,"lowercase":true,"digits":true,"counter":1,"version":2,"length":16}"#);
let response = request.dispatch().await;
assert_eq!(response.status(), Status::InternalServerError);
// Check that the password to be changed has the following default values
Expand All @@ -418,7 +418,7 @@ mod tests {
let request = client.put("/passwords/1")
.header(ContentType::JSON)
.header(Header::new("authorization", format!("bearer {}", token.access)))
.body(r#"{"login":"[email protected]","site":"rockpass.sample","uppercase":false,"symbols":true,"lowercase":true,"numbers":true,"counter":2,"version":2,"length":16}"#);
.body(r#"{"login":"[email protected]","site":"rockpass.sample","uppercase":false,"symbols":true,"lowercase":true,"digits":true,"counter":2,"version":2,"length":16}"#);
let response = request.dispatch().await;
assert_eq!(response.status(), Status::Created);
assert_eq!(response.into_string().await.unwrap(), r#"{"detail":"Updated password entry for site rockpass.sample"}"#);
Expand Down
4 changes: 2 additions & 2 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct Password {
pub uppercase: bool,
pub symbols: bool,
pub lowercase: bool,
pub numbers: bool,
pub digits: bool,
pub counter: i32,
pub version: i32,
pub length: i32,
Expand Down Expand Up @@ -103,7 +103,7 @@ pub struct NewPassword {
pub symbols: bool,
pub lowercase: bool,
#[serde(deserialize_with = "digits_or_numbers", flatten)]
pub numbers: bool,
pub digits: bool,
pub counter: i32,
#[serde(default = "default_version")]
pub version: i32,
Expand Down
14 changes: 7 additions & 7 deletions src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
table! {
diesel::table! {
passwords (id) {
id -> Integer,
user_id -> Integer,
Expand All @@ -7,7 +7,7 @@ table! {
uppercase -> Bool,
symbols -> Bool,
lowercase -> Bool,
numbers -> Bool,
digits -> Bool,
counter -> Integer,
version -> Integer,
length -> Integer,
Expand All @@ -16,7 +16,7 @@ table! {
}
}

table! {
diesel::table! {
tokens (id) {
id -> Integer,
user_id -> Integer,
Expand All @@ -27,18 +27,18 @@ table! {
}
}

table! {
diesel::table! {
users (id) {
id -> Integer,
email -> Text,
password -> Text,
}
}

joinable!(passwords -> users (user_id));
joinable!(tokens -> users (user_id));
diesel::joinable!(passwords -> users (user_id));
diesel::joinable!(tokens -> users (user_id));

allow_tables_to_appear_in_same_query!(
diesel::allow_tables_to_appear_in_same_query!(
passwords,
tokens,
users,
Expand Down

0 comments on commit 300e246

Please sign in to comment.