Browse code
created conversation class
Greg Wiley authored on 13/04/2017 18:14:17
Showing 4 changed files
Showing 4 changed files
... | ... |
@@ -45,12 +45,13 @@ user_test: user_test.o t_user.o |
45 | 45 |
validator_test: validator_test.o t_validator.o |
46 | 46 |
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ |
47 | 47 |
|
48 |
- |
|
48 |
+conversation_test: conversation_test.o t_conversation.o |
|
49 |
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ |
|
49 | 50 |
|
50 | 51 |
.PHONY: test |
51 |
-test: validator_test |
|
52 |
+test: validator_test conversation_test |
|
52 | 53 |
@./validator_test |
53 |
- |
|
54 |
+ @./conversation_test |
|
54 | 55 |
|
55 | 56 |
# @./dual_control_test |
56 | 57 |
# @./logging_test |
... | ... |
@@ -2,20 +2,21 @@ |
2 | 2 |
#define _CONVERSATION_H |
3 | 3 |
|
4 | 4 |
#include <security/pam_modules.h> |
5 |
+#include <string> |
|
6 |
+ |
|
5 | 7 |
|
6 | 8 |
class token_conversation { |
7 | 9 |
public: |
8 | 10 |
virtual ~token_conversation() {} |
9 |
- virtual std::string token() = 0; |
|
10 |
- virtual std::string user_name() = 0; |
|
11 |
-} |
|
11 |
+ virtual std::string token() { return""; } |
|
12 |
+ virtual std::string user_name() { return ""; } |
|
13 |
+}; |
|
12 | 14 |
|
13 | 15 |
class pam_token_conversation : token_conversation { |
14 | 16 |
public: |
15 | 17 |
pam_token_conversation(pam_handle_t *pamh); |
16 |
-} |
|
17 |
- |
|
18 |
-char const *ask_for_token(pam_handle_t *pamh); |
|
18 |
+ std::string token(); |
|
19 |
+}; |
|
19 | 20 |
|
20 | 21 |
#endif |
21 | 22 |
|
22 | 23 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,33 @@ |
1 |
+#include <security/pam_modules.h> |
|
2 |
+ |
|
3 |
+#include "conversation.h" |
|
4 |
+#include "test_util.h" |
|
5 |
+ |
|
6 |
+ |
|
7 |
+int returns_correct_token() { |
|
8 |
+ //given |
|
9 |
+ pam_handle_t *pamh; |
|
10 |
+ |
|
11 |
+ //when |
|
12 |
+ pam_token_conversation conversation(pamh); |
|
13 |
+ |
|
14 |
+ //then |
|
15 |
+ check(conversation.token() == "token", "returned incorrect token"); |
|
16 |
+ succeed(); |
|
17 |
+} |
|
18 |
+ |
|
19 |
+ |
|
20 |
+ |
|
21 |
+RESET_VARS_START |
|
22 |
+RESET_VARS_END |
|
23 |
+ |
|
24 |
+int run_tests() { |
|
25 |
+ test(returns_correct_token); |
|
26 |
+ succeed(); |
|
27 |
+} |
|
28 |
+ |
|
29 |
+int main(int argc, char *args[]) { |
|
30 |
+ return !run_tests(); |
|
31 |
+} |
|
32 |
+ |
|
33 |
+ |