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.
5 #ifndef NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_H_
6 #define NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_H_
13 #include "base/android/scoped_java_ref.h"
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.
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
26 class gss_buffer_desc
;
28 typedef struct gss_OID_desc_struct
{
31 } gss_OID_desc
, *gss_OID
;
33 extern gss_OID CHROME_GSS_SPNEGO_MECH_OID_DESC
;
37 // Copy of class in Mock GSSAPI library.
38 class 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
,
47 int locally_initiated
,
49 ~GssContextMockImpl();
51 void Assign(const GssContextMockImpl
& other
);
54 std::string targ_name
;
56 gss_OID_desc mech_type
;
58 int locally_initiated
;
66 // Interface to Java DummySpnegoAuthenticator.
67 class DummySpnegoAuthenticator
{
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();
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
;
95 // Java callable members
96 base::android::ScopedJavaLocalRef
<jstring
> GetTokenToReturn(JNIEnv
* env
,
98 int GetResult(JNIEnv
* env
, jobject obj
);
100 // Called from Java to check the arguments passed to the GetToken. Has to
101 // be in C++ since these tests are driven by googletest, and can only report
102 // failures through the googletest C++ API.
103 void CheckGetTokenArguments(JNIEnv
* env
,
105 jstring incoming_token
);
108 DummySpnegoAuthenticator();
110 ~DummySpnegoAuthenticator();
112 void ExpectSecurityContext(const std::string
& expected_package
,
113 uint32_t response_code
,
114 uint32_t minor_response_code
,
115 const test::GssContextMockImpl
& context_info
,
116 const std::string
& expected_input_token
,
117 const std::string
& output_token
);
119 static bool RegisterJni(JNIEnv
* env
);
121 static void EnsureTestAccountExists();
122 static void RemoveTestAccounts();
124 long GetNextQuery(JNIEnv
* env
, jobject obj
);
127 // Abandon the test if the query queue is empty. Has to be a void function to
128 // allow use of ASSERT_FALSE.
129 void CheckQueueNotEmpty();
131 std::list
<SecurityContextQuery
> expected_security_queries_
;
132 // Needed to keep the current query alive once it has been pulled from the
133 // queue. This is simpler than transferring its ownership to Java.
134 SecurityContextQuery current_query_
;
137 } // namespace android
140 #endif // NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_DRIVER_H