OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_H_ | |
6 #define NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_H_ | |
7 | |
8 #include <jni.h> | |
9 #include <cstdint> | |
10 #include <list> | |
11 #include <string> | |
12 | |
13 #include "base/android/scoped_java_ref.h" | |
14 | |
15 // Provides an interface for controlling the DummySpnegoAuthenticator service. | |
16 // This includes a basic stub of the Mock GSSAPI library, so that OS independent | |
17 // Negotiate authentication tests can be run on Android. | |
18 namespace net { | |
19 | |
20 // These constant values are arbitrary, and different from the real GSSAPI | |
21 // values, but must match those used in DummySpnegoAuthenticator.java | |
22 #define GSS_S_COMPLETE 0 | |
23 #define GSS_S_CONTINUE_NEEDED 1 | |
24 #define GSS_S_FAILURE 2 | |
25 | |
26 class gss_buffer_desc; | |
27 | |
28 typedef struct gss_OID_desc_struct { | |
29 uint32_t length; | |
30 void* elements; | |
31 } gss_OID_desc, *gss_OID; | |
32 | |
33 extern gss_OID CHROME_GSS_SPNEGO_MECH_OID_DESC; | |
34 | |
35 namespace test { | |
36 | |
37 // Copy of class in Mock GSSAPI library. | |
38 class GssContextMockImpl { | |
39 public: | |
40 GssContextMockImpl(); | |
41 GssContextMockImpl(const GssContextMockImpl& other); | |
42 GssContextMockImpl(const char* src_name, | |
43 const char* targ_name, | |
44 uint32_t lifetime_rec, | |
45 const gss_OID_desc& mech_type, | |
46 uint32_t ctx_flags, | |
47 int locally_initiated, | |
48 int open); | |
49 ~GssContextMockImpl(); | |
50 | |
51 void Assign(const GssContextMockImpl& other); | |
52 | |
53 std::string src_name; | |
54 std::string targ_name; | |
55 int32_t lifetime_rec; | |
56 gss_OID_desc mech_type; | |
57 int32_t ctx_flags; | |
58 int locally_initiated; | |
59 int open; | |
60 }; | |
61 | |
62 } // namespace test | |
63 | |
64 namespace android { | |
65 | |
66 // Interface to Java DummySpnegoAuthenticator. | |
67 class DummySpnegoAuthenticator { | |
68 public: | |
69 struct SecurityContextQuery { | |
70 SecurityContextQuery(const std::string& expected_package, | |
71 uint32_t response_code, | |
72 uint32_t minor_response_code, | |
73 const test::GssContextMockImpl& context_info, | |
74 const std::string& expected_input_token, | |
75 const std::string& output_token); | |
76 SecurityContextQuery(const std::string& expected_package, | |
77 uint32_t response_code, | |
78 uint32_t minor_response_code, | |
79 const test::GssContextMockImpl& context_info, | |
80 const char* expected_input_token, | |
81 const char* output_token); | |
82 SecurityContextQuery(); | |
83 ~SecurityContextQuery(); | |
84 | |
85 // Note that many of these fields only exist for compatibility with the | |
86 // non-Android version of the tests. Only the response_code and tokens are | |
87 // used or checked on Android. | |
88 std::string expected_package; | |
89 uint32_t response_code; | |
90 uint32_t minor_response_code; | |
91 test::GssContextMockImpl context_info; | |
92 std::string expected_input_token; | |
93 std::string output_token; | |
94 | |
95 // Java callable members | |
96 base::android::ScopedJavaLocalRef<jstring> GetTokenToReturn(JNIEnv* env, | |
97 jobject obj); | |
98 int GetResult(JNIEnv* env, jobject obj); | |
99 | |
100 // Called from Java to check the arguments passed to the GetToken. Has to | |
101 // be in C++ since we want to cause googletest failures if they are wrong. | |
cbentzel
2015/07/08 18:27:11
Nit: Remove "we" in comment. Something like "Has t
aberent
2015/07/09 13:38:45
Done.
| |
102 void CheckGetTokenArguments(JNIEnv* env, | |
103 jobject obj, | |
104 jstring incoming_token); | |
105 }; | |
106 | |
107 DummySpnegoAuthenticator(); | |
108 | |
109 ~DummySpnegoAuthenticator(); | |
110 | |
111 void ExpectSecurityContext(const std::string& expected_package, | |
112 uint32_t response_code, | |
113 uint32_t minor_response_code, | |
114 const test::GssContextMockImpl& context_info, | |
115 const std::string& expected_input_token, | |
116 const std::string& output_token); | |
117 | |
118 static bool RegisterJni(JNIEnv* env); | |
119 | |
120 static void EnsureTestAccountExists(); | |
121 static void RemoveTestAccounts(); | |
122 | |
123 long GetNextQuery(JNIEnv* env, jobject obj); | |
124 | |
125 private: | |
126 // Abandon the test if the query queue is empty. Has to be a void function to | |
127 // allow use of ASSERT_FALSE. | |
128 void CheckQueueNotEmpty(); | |
129 | |
130 std::list<SecurityContextQuery> expected_security_queries_; | |
131 // Needed to keep the current query alive once it has been pulled from the | |
132 // queue. This is simpler than transferring its ownership to Java. | |
133 SecurityContextQuery current_query_; | |
134 }; | |
135 | |
136 } // namespace android | |
137 } // namespace net | |
138 | |
139 #endif // NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_DRIVER_H | |
OLD | NEW |