aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml12
-rw-r--r--Makefile9
-rw-r--r--tests/web.rs55
3 files changed, 71 insertions, 5 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6655399..176339b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,17 @@
image: alpine:3
+stages:
+ - test
+
+test:
+ before_script:
+ - export PATH="$PATH:$HOME/.cargo/bin"
+ - apk add npm make curl build-base firefox
+ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --quiet -y
+ - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
+ script:
+ - make test
+
pages:
before_script:
- export PATH="$PATH:$HOME/.cargo/bin"
diff --git a/Makefile b/Makefile
index 5ae5e87..795de5c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,15 @@
-all: cargo
+all: wasm
cd www && \
npm install && \
npm run build
-serve: cargo
+serve: wasm
cd www && \
npm install && \
npm run start
-cargo:
+wasm:
wasm-pack build --no-typescript --release
+
+test:
+ wasm-pack test --headless --firefox
diff --git a/tests/web.rs b/tests/web.rs
index de5c1da..607f16d 100644
--- a/tests/web.rs
+++ b/tests/web.rs
@@ -3,11 +3,62 @@
#![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);
+ assert_eq!(x, password.len())
+ }
+}
+
+#[wasm_bindgen_test]
+fn generate_not_upper_letters() {
+ let lower_charset = "abcdefghijklmnopqrstuvwxyz";
+ for _ in 0..ATTEMPTS {
+ let password = generate(100, false, true, true, true);
+ for char in String::from(lower_charset).chars().into_iter() {
+ assert!(!password.contains(char))
+ }
+ }
+}
+
+#[wasm_bindgen_test]
+fn generate_not_lower_letters() {
+ let upper_charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ for x in 0..ATTEMPTS {
+ let password = generate(x, true, false, true, true);
+ for char in String::from(upper_charset).chars().into_iter() {
+ assert!(!password.contains(char))
+ }
+ }
+}
+
+#[wasm_bindgen_test]
+fn generate_not_number_letters() {
+ let upper_charset = "1234567890";
+ for x in 0..ATTEMPTS {
+ let password = generate(x, true, true, false, true);
+ for char in String::from(upper_charset).chars().into_iter() {
+ assert!(!password.contains(char))
+ }
+ }
+}
+
#[wasm_bindgen_test]
-fn pass() {
- assert_eq!(1 + 1, 2);
+fn generate_not_special_letters() {
+ let upper_charset = "!@#$%^&*()+{}[]";
+ for x in 0..ATTEMPTS {
+ let password = generate(x, true, true, true, false);
+ for char in String::from(upper_charset).chars().into_iter() {
+ assert!(!password.contains(char))
+ }
+ }
}