Skip to content

Commit 5a0018c

Browse files
committed
test threaded GSSAPI auth
This test of Cyrus SASL's GSSAPI Kerberos auth wasn't running in Evergreen. Split it to a separate test program and run it with the other auth tests. Also, only compile test-mongoc-cyrus.c if we are using Cyrus SASL.
1 parent 35c200a commit 5a0018c

File tree

7 files changed

+175
-136
lines changed

7 files changed

+175
-136
lines changed

.evergreen/run-auth-tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ case "$OS" in
3131
export PATH=$PATH:`pwd`/tests:`pwd`/Debug:`pwd`/src/libbson/Debug
3232
chmod +x ./Debug/* src/libbson/Debug/*
3333
PING="./Debug/mongoc-ping.exe"
34+
TEST_GSSAPI="./Debug/test-mongoc-gssapi.exe"
3435
;;
3536

3637
darwin)
3738
sed -i'.bak' 's/\/data\/mci\/[a-z0-9]\{32\}\/mongoc/./g' mongoc-ping
39+
sed -i'.bak' 's/\/data\/mci\/[a-z0-9]\{32\}\/mongoc/./g' test-mongoc-gssapi
3840
export DYLD_LIBRARY_PATH="install-dir/lib:.libs:src/libbson/.libs"
3941
PING="./mongoc-ping"
42+
TEST_GSSAPI="./test-mongoc-gssapi"
4043
;;
4144

4245
*)
4346
# This libtool wrapper script was built in a unique dir like
4447
# "/data/mci/998e754a0d1ed79b8bf733f405b87778/mongoc",
4548
# replace its absolute path with "." so it can run in the CWD.
4649
sed -i'' 's/\/data\/mci\/[a-z0-9]\{32\}\/mongoc/./g' mongoc-ping
50+
sed -i'' 's/\/data\/mci\/[a-z0-9]\{32\}\/mongoc/./g' test-mongoc-gssapi
4751
export LD_LIBRARY_PATH="install-dir/lib:.libs:src/libbson/.libs"
4852
PING="./mongoc-ping"
53+
TEST_GSSAPI="./test-mongoc-gssapi"
4954
esac
5055

5156
if test -f /tmp/drivers.keytab; then
@@ -87,6 +92,9 @@ $PING "mongodb://${AUTH_MONGODBCR}@${AUTH_HOST}/mongodb-cr?authMechanism=MONGODB
8792
if [ $SASL -eq 1 ]; then
8893
echo "Authenticating using GSSAPI"
8994
$PING "mongodb://${AUTH_GSSAPI}@${AUTH_HOST}/?authMechanism=GSSAPI&${C_TIMEOUT}"
95+
echo "Test threaded GSSAPI auth"
96+
MONGOC_TEST_GSSAPI_HOST="${AUTH_HOST}" MONGOC_TEST_GSSAPI_USER="${AUTH_GSSAPI}" $TEST_GSSAPI
97+
echo "Threaded GSSAPI auth OK"
9098
if [ "${OS%_*}" = "cygwin" ]; then
9199
echo "Authenticating using GSSAPI (service realm: LDAPTEST.10GEN.CC)"
92100
$PING "mongodb://${AUTH_CROSSREALM}@${AUTH_HOST}/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_REALM:LDAPTEST.10GEN.CC&${C_TIMEOUT}"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ test-mongoc-stream
9595
test-mongoc-stream-tls
9696
test-mongoc-uri
9797
test-mongoc-write-concern
98+
test-mongoc-gssapi
9899
# Windows things
99100
*.dir
100101
*.vcxproj*

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,14 @@ if (MONGOC_ENABLE_SSL)
768768
${SOURCE_DIR}/tests/test-mongoc-stream-tls-error.c)
769769
endif()
770770

771-
if (MONGOC_ENABLE_SASL)
771+
if (MONGOC_ENABLE_SASL_CYRUS)
772772
set(test-libmongoc-sources ${test-libmongoc-sources}
773773
${SOURCE_DIR}/tests/test-mongoc-cyrus.c
774774
)
775775
endif ()
776776

777777
mongoc_add_test(test-libmongoc FALSE ${test-libmongoc-sources})
778+
mongoc_add_test (test-mongoc-gssapi TRUE ${SOURCE_DIR}/tests/test-mongoc-gssapi.c)
778779

779780
if (ENABLE_TESTS)
780781
enable_testing()

tests/Makefile.am

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test_libmongoc_SOURCES += \
129129
tests/ssl-test.h
130130
endif
131131

132-
if ENABLE_SASL
132+
if ENABLE_SASL_CYRUS
133133
test_libmongoc_SOURCES += \
134134
tests/test-mongoc-cyrus.c
135135
endif
@@ -138,7 +138,12 @@ test_libmongoc_LDADD = libmongoc.la $(TEST_LIBS)
138138
test_libmongoc_LDFLAGS = -no-undefined \
139139
-rpath $(libdir)
140140

141-
141+
noinst_PROGRAMS += test-mongoc-gssapi
142+
test_mongoc_gssapi_SOURCES = tests/test-mongoc-gssapi.c
143+
test_mongoc_gssapi_CFLAGS = $(TEST_CFLAGS)
144+
test_mongoc_gssapi_LDADD = libmongoc.la $(TEST_LIBS)
145+
test_mongoc_gssapi_LDFLAGS = -no-undefined \
146+
-rpath $(libdir)
142147

143148
check: test
144149

tests/test-libmongoc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ test_x509_install (TestSuite *suite);
147147
extern void
148148
test_stream_tls_error_install (TestSuite *suite);
149149
#endif
150-
#ifdef MONGOC_ENABLE_SASL
150+
#ifdef MONGOC_ENABLE_SASL_CYRUS
151151
extern void
152-
test_sasl_install (TestSuite *suite);
152+
test_cyrus_install (TestSuite *suite);
153153
#endif
154154

155155

@@ -2169,8 +2169,8 @@ main (int argc, char *argv[])
21692169
test_x509_install (&suite);
21702170
test_stream_tls_error_install (&suite);
21712171
#endif
2172-
#ifdef MONGOC_ENABLE_SASL
2173-
test_sasl_install (&suite);
2172+
#ifdef MONGOC_ENABLE_SASL_CYRUS
2173+
test_cyrus_install (&suite);
21742174
#endif
21752175

21762176
ret = TestSuite_Run (&suite);

tests/test-mongoc-cyrus.c

Lines changed: 2 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -15,131 +15,13 @@
1515
*/
1616

1717
#include <mongoc.h>
18-
#include <mongoc-thread-private.h>
19-
#ifdef MONGOC_ENABLE_SASL_CYRUS
2018
#include <mongoc-cyrus-private.h>
2119
#include <mongoc-client-private.h>
2220

23-
#endif
24-
2521
#include "TestSuite.h"
2622
#include "test-libmongoc.h"
2723

2824

29-
static const char *GSSAPI_HOST = "MONGOC_TEST_GSSAPI_HOST";
30-
static const char *GSSAPI_USER = "MONGOC_TEST_GSSAPI_USER";
31-
32-
#define NTHREADS 10
33-
#define NLOOPS 10
34-
35-
36-
int
37-
should_run_gssapi_kerberos (void)
38-
{
39-
char *host = test_framework_getenv (GSSAPI_HOST);
40-
char *user = test_framework_getenv (GSSAPI_USER);
41-
int ret = (host && user);
42-
43-
bson_free (host);
44-
bson_free (user);
45-
46-
return ret;
47-
}
48-
49-
50-
struct closure_t {
51-
mongoc_client_pool_t *pool;
52-
int finished;
53-
mongoc_mutex_t mutex;
54-
};
55-
56-
57-
static void *
58-
gssapi_kerberos_worker (void *data)
59-
{
60-
struct closure_t *closure = (struct closure_t *) data;
61-
mongoc_client_pool_t *pool = closure->pool;
62-
mongoc_client_t *client;
63-
mongoc_collection_t *collection;
64-
mongoc_cursor_t *cursor;
65-
bson_error_t error;
66-
const bson_t *doc;
67-
bson_t query = BSON_INITIALIZER;
68-
int i;
69-
70-
for (i = 0; i < NLOOPS; i++) {
71-
client = mongoc_client_pool_pop (pool);
72-
collection = mongoc_client_get_collection (client, "kerberos", "test");
73-
cursor = mongoc_collection_find (
74-
collection, MONGOC_QUERY_NONE, 0, 0, 0, &query, NULL, NULL);
75-
76-
if (!mongoc_cursor_next (cursor, &doc) &&
77-
mongoc_cursor_error (cursor, &error)) {
78-
fprintf (stderr, "Cursor Failure: %s\n", error.message);
79-
abort ();
80-
}
81-
82-
mongoc_cursor_destroy (cursor);
83-
mongoc_collection_destroy (collection);
84-
mongoc_client_pool_push (pool, client);
85-
}
86-
87-
bson_destroy (&query);
88-
89-
mongoc_mutex_lock (&closure->mutex);
90-
closure->finished++;
91-
mongoc_mutex_unlock (&closure->mutex);
92-
93-
return NULL;
94-
}
95-
96-
97-
static void
98-
test_gssapi_kerberos (void *context)
99-
{
100-
char *host = test_framework_getenv (GSSAPI_HOST);
101-
char *user = test_framework_getenv (GSSAPI_USER);
102-
char *uri_str;
103-
mongoc_uri_t *uri;
104-
struct closure_t closure = {0};
105-
int i;
106-
mongoc_thread_t threads[NTHREADS];
107-
108-
BSON_ASSERT (host && user);
109-
110-
mongoc_mutex_init (&closure.mutex);
111-
112-
uri_str = bson_strdup_printf (
113-
"mongodb://%s@%s/?authMechanism=GSSAPI&serverselectiontimeoutms=1000",
114-
user,
115-
host);
116-
117-
uri = mongoc_uri_new (uri_str);
118-
closure.pool = mongoc_client_pool_new (uri);
119-
120-
for (i = 0; i < NTHREADS; i++) {
121-
mongoc_thread_create (
122-
&threads[i], gssapi_kerberos_worker, (void *) &closure);
123-
}
124-
125-
for (i = 0; i < NTHREADS; i++) {
126-
mongoc_thread_join (threads[i]);
127-
}
128-
129-
mongoc_mutex_lock (&closure.mutex);
130-
ASSERT_CMPINT (NTHREADS, ==, closure.finished);
131-
mongoc_mutex_unlock (&closure.mutex);
132-
133-
mongoc_client_pool_destroy (closure.pool);
134-
mongoc_mutex_destroy (&closure.mutex);
135-
mongoc_uri_destroy (uri);
136-
bson_free (uri_str);
137-
bson_free (host);
138-
bson_free (user);
139-
}
140-
141-
142-
#ifdef MONGOC_ENABLE_SASL_CYRUS
14325
static void
14426
test_sasl_properties (void)
14527
{
@@ -203,26 +85,17 @@ test_sasl_canonicalize_hostname (void *ctx)
20385
mongoc_server_stream_cleanup (ss);
20486
mongoc_client_destroy (client);
20587
}
206-
#endif
20788

20889

20990
void
210-
test_sasl_install (TestSuite *suite)
91+
test_cyrus_install (TestSuite *suite)
21192
{
212-
TestSuite_AddFull (suite,
213-
"/SASL/gssapi_kerberos",
214-
test_gssapi_kerberos,
215-
NULL,
216-
NULL,
217-
should_run_gssapi_kerberos);
218-
#ifdef MONGOC_ENABLE_SASL_CYRUS
93+
TestSuite_Add (suite, "/SASL/properties", test_sasl_properties);
21994
TestSuite_AddFull (suite,
22095
"/SASL/canonicalize",
22196
test_sasl_canonicalize_hostname,
22297
NULL,
22398
NULL,
22499
TestSuite_CheckLive,
225100
test_framework_skip_if_offline);
226-
TestSuite_Add (suite, "/SASL/properties", test_sasl_properties);
227-
#endif
228101
}

0 commit comments

Comments
 (0)