aboutsummaryrefslogtreecommitdiff
path: root/tests/web.rs
blob: b5af03452317cb8b55547ad613a7c7a5afb74cc9 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Test suite for the Web and headless browsers.

#![cfg(target_arch = "wasm32")]

extern crate wasm_bindgen_test;

use wasm_bindgen_test::*;
use genpass::generate;

wasm_bindgen_test_configure!(run_in_browser);

const ATTEMPTS: usize = 5;

#[wasm_bindgen_test]
fn generate_length() {
    for x in (0..=100).step_by(5) {
        let password = generate(x, true, true, true, true, false);
        assert_eq!(x, password.len())
    }
}

#[wasm_bindgen_test]
fn generate_no_upper_letters() {
    let charset = "abcdefghijklmnopqrstuvwxyz";
    for _ in 0..ATTEMPTS {
        let password = generate(100, false, true, true, true, true);
        for char in String::from(charset).chars().into_iter() {
            assert!(!password.contains(char))
        }
    }
}

#[wasm_bindgen_test]
fn generate_no_lower_letters() {
    let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for x in 0..ATTEMPTS {
        let password = generate(x, true, false, true, true, true);
        for char in String::from(charset).chars().into_iter() {
            assert!(!password.contains(char))
        }
    }
}

#[wasm_bindgen_test]
fn generate_no_number_letters() {
    let charset = "1234567890";
    for x in 0..ATTEMPTS {
        let password = generate(x, true, true, false, true, true);
        for char in String::from(charset).chars().into_iter() {
            assert!(!password.contains(char))
        }
    }
}

#[wasm_bindgen_test]
fn generate_no_special_letters() {
    let charset = "!@#$%^&*()+{}[]><:|+=;-.,'?_~\\/`\"";
    for x in 0..ATTEMPTS {
        let password = generate(x, true, true, true, false, true);
        for char in String::from(charset).chars().into_iter() {
            assert!(!password.contains(char))
        }
    }
}

#[wasm_bindgen_test]
fn generate_no_extended_letters() {
    let charset = "®û´¢æ«æëàñîêáö½¬èñý¹áúóâªò×ä¸ÿ¦ù°º±¨åûïøí»§÷î¤ã¡òþ¿³óùçâüëíõôéðìö¶þ¾úý·êéãߣüèðµå¥õïà¼øäô©²¯çì";
    for x in 0..ATTEMPTS {
        let password = generate(x, true, true, true, true, false);
        for char in String::from(charset).chars().into_iter() {
            assert!(!password.contains(char))
        }
    }
}

#[wasm_bindgen_test]
fn generate_0_len() {
    let password = generate(0, true, true, true, true, true);
    assert_eq!(0, password.len())
}

#[wasm_bindgen_test]
fn generate_no_letters() {
    let password = generate(100, false, false, false, false, true);
    assert_eq!(0, password.len())
}