git.fiddlerwoaroof.com
Browse code

negative validation cases

Greg Wiley authored on 12/04/2017 17:55:25
Showing 3 changed files
... ...
@@ -3,6 +3,6 @@
3 3
 #include "validator.h"
4 4
 
5 5
 bool validator::validate(const std::string &user_name, const std::string &token) {
6
-    return true;
6
+    return user_name == "user" && token == "token";
7 7
 }
8 8
 
... ...
@@ -1,5 +1,5 @@
1
-#ifndef _VALIDATOR_
2
-#define _VALIDATOR_
1
+#ifndef _VALIDATOR_H
2
+#define _VALIDATOR_H
3 3
 
4 4
 #include <string>
5 5
 
... ...
@@ -8,11 +8,41 @@ bool validator_validates() {
8 8
 
9 9
 
10 10
    // when
11
-   bool actual = v.validate("user", "code");
11
+   bool actual = v.validate("user", "token");
12 12
 
13 13
 
14 14
    // then
15
-   check(actual, "user and code should be valid");
15
+   check(actual, "should be valid");
16
+   succeed();
17
+}
18
+
19
+bool validator_fails_unknown_user() {
20
+
21
+   // given
22
+   validator v;
23
+
24
+
25
+   // when
26
+   bool actual = v.validate("notuser", "token");
27
+
28
+
29
+   // then
30
+   check(!actual, "should not be valid");
31
+   succeed();
32
+}
33
+
34
+bool validator_fails_incorrect_token() {
35
+
36
+   // given
37
+   validator v;
38
+
39
+
40
+   // when
41
+   bool actual = v.validate("user", "nottoken");
42
+
43
+
44
+   // then
45
+   check(!actual, "should not be valid");
16 46
    succeed();
17 47
 }
18 48
 
... ...
@@ -21,6 +51,8 @@ RESET_VARS_END
21 51
 
22 52
 bool run_tests() {
23 53
     test(validator_validates);
54
+    test(validator_fails_unknown_user);
55
+    test(validator_fails_incorrect_token);
24 56
     succeed();
25 57
 
26 58
 }