#ifndef NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_H_
#define NET_ANDROID_DUMMY_SPNEGO_AUTHENTICATOR_H_
#include <jni.h>
#include <stdint.h>
#include <list>
#include <string>
#include "base/android/scoped_java_ref.h"
#include "base/memory/raw_ptr_exclusion.h"
namespace net {
#define GSS_S_COMPLETE 0
#define GSS_S_CONTINUE_NEEDED 1
#define GSS_S_FAILURE 2
typedef struct gss_OID_desc_struct {
uint32_t length;
RAW_PTR_EXCLUSION void* elements;
} gss_OID_desc, *gss_OID;
extern gss_OID CHROME_GSS_SPNEGO_MECH_OID_DESC;
namespace test {
class GssContextMockImpl {
public:
GssContextMockImpl();
GssContextMockImpl(const GssContextMockImpl& other);
GssContextMockImpl(const char* src_name,
const char* targ_name,
uint32_t lifetime_rec,
const gss_OID_desc& mech_type,
uint32_t ctx_flags,
int locally_initiated,
int open);
~GssContextMockImpl();
void Assign(const GssContextMockImpl& other);
std::string src_name;
std::string targ_name;
int32_t lifetime_rec;
gss_OID_desc mech_type;
int32_t ctx_flags;
int locally_initiated;
int open;
};
}
namespace android {
class DummySpnegoAuthenticator {
public:
struct SecurityContextQuery {
SecurityContextQuery(const std::string& expected_package,
uint32_t response_code,
uint32_t minor_response_code,
const test::GssContextMockImpl& context_info,
const std::string& expected_input_token,
const std::string& output_token);
SecurityContextQuery(const std::string& expected_package,
uint32_t response_code,
uint32_t minor_response_code,
const test::GssContextMockImpl& context_info,
const char* expected_input_token,
const char* output_token);
SecurityContextQuery();
SecurityContextQuery(const SecurityContextQuery& other);
~SecurityContextQuery();
std::string expected_package;
uint32_t response_code;
uint32_t minor_response_code;
test::GssContextMockImpl context_info;
std::string expected_input_token;
std::string output_token;
base::android::ScopedJavaLocalRef<jstring> GetTokenToReturn(JNIEnv* env);
int GetResult(JNIEnv* env);
void CheckGetTokenArguments(
JNIEnv* env,
const base::android::JavaParamRef<jstring>& incoming_token);
};
DummySpnegoAuthenticator();
~DummySpnegoAuthenticator();
void ExpectSecurityContext(const std::string& expected_package,
uint32_t response_code,
uint32_t minor_response_code,
const test::GssContextMockImpl& context_info,
const std::string& expected_input_token,
const std::string& output_token);
static void EnsureTestAccountExists();
static void RemoveTestAccounts();
long GetNextQuery(JNIEnv* env);
private:
void CheckQueueNotEmpty();
std::list<SecurityContextQuery> expected_security_queries_;
SecurityContextQuery current_query_;
};
}
using MockAuthLibrary = android::DummySpnegoAuthenticator;
}
#endif