-
Notifications
You must be signed in to change notification settings - Fork 8
/
django42.rs
55 lines (51 loc) · 1.95 KB
/
django42.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! This is an almost line-by-line translation from the hashers' test from Django 4.2:
//! https://github.com/django/django/blob/master/tests/auth_tests/test_hashers.py
//! ...but only for the tests where the iterations differ from Django 1.9.
use djangohashers::*;
#[test]
#[cfg(feature = "with_pbkdf2")]
fn test_pbkdf2() {
let django = Django {
version: DjangoVersion::V4_2,
};
let encoded = django.make_password_with_settings("lètmein", "seasalt", Algorithm::PBKDF2);
assert_eq!(
encoded,
"pbkdf2_sha256$600000$seasalt$OAXyhAQ/4ZDA9V5RMExt3C1OwQdUpLZ99vm1McFlLRA="
);
assert!(is_password_usable(&encoded));
assert_eq!(check_password("lètmein", &encoded), Ok(true));
assert_eq!(check_password("lètmeinz", &encoded), Ok(false));
// Blank passwords
let blank_encoded = django.make_password_with_settings("", "seasalt", Algorithm::PBKDF2);
assert!(blank_encoded.starts_with("pbkdf2_sha256$"));
assert!(is_password_usable(&blank_encoded));
assert_eq!(check_password("", &blank_encoded), Ok(true));
assert_eq!(check_password(" ", &blank_encoded), Ok(false));
}
#[test]
#[cfg(feature = "with_pbkdf2")]
fn test_low_level_pbkdf2() {
let django = Django {
version: DjangoVersion::V4_2,
};
let encoded = django.make_password_with_settings("lètmein", "seasalt2", Algorithm::PBKDF2);
assert_eq!(
encoded,
"pbkdf2_sha256$600000$seasalt2$OSllgFdJjYQjb0RfMzrx8u0XYl4Fkt+wKpI1yq4lZlo="
);
assert_eq!(check_password("lètmein", &encoded), Ok(true));
}
#[test]
#[cfg(feature = "with_pbkdf2")]
fn test_low_level_pbkdf2_sha1() {
let django = Django {
version: DjangoVersion::V4_2,
};
let encoded = django.make_password_with_settings("lètmein", "seasalt2", Algorithm::PBKDF2SHA1);
assert_eq!(
encoded,
"pbkdf2_sha1$600000$seasalt2$2CLsaL1MZhq6JOG6QOHtVbiopHE="
);
assert_eq!(check_password("lètmein", &encoded), Ok(true));
}