Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sso
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ai
sso
Commits
ce1b9de7
Commit
ce1b9de7
authored
Aug 12, 2013
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick test for thread safety of the main SSO API
parent
c8c2bb63
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
src/sso/test/Makefile.am
src/sso/test/Makefile.am
+3
-0
src/sso/test/thread_safety_test.cc
src/sso/test/thread_safety_test.cc
+61
-0
No files found.
src/sso/test/Makefile.am
View file @
ce1b9de7
...
...
@@ -5,6 +5,7 @@ check_PROGRAMS = \
string_utils_unittest
\
sso_unittest
\
ticket_unittest
\
thread_safety_test
\
signer_unittest
\
verifier_unittest
...
...
@@ -24,3 +25,5 @@ sso_unittest_SOURCES = sso_unittest.cc
signer_unittest_SOURCES
=
signer_unittest.cc
verifier_unittest_SOURCES
=
verifier_unittest.cc
thread_safety_test_SOURCES
=
thread_safety_test.cc
src/sso/test/thread_safety_test.cc
0 → 100644
View file @
ce1b9de7
#include <pthread.h>
#include <gtest/gtest.h>
#include "sso.h"
#include "test_common.h"
#define NCHECKS 100
#define NTHREADS 10
namespace
{
struct
TestContext
{
sso
::
Signer
*
signer
;
sso
::
Verifier
*
verifier
;
};
static
void
*
test_signer
(
void
*
ctxptr
)
{
TestContext
*
ctx
=
reinterpret_cast
<
TestContext
*>
(
ctxptr
);
sso
::
Ticket
t
(
"user1"
,
"service"
,
"domain"
);
std
::
string
signed_ticket
=
ctx
->
signer
->
sign
(
&
t
);
for
(
int
i
=
0
;
i
<
NCHECKS
;
i
++
)
{
try
{
sso
::
Ticket
*
t2
=
ctx
->
verifier
->
verify
(
signed_ticket
);
delete
t2
;
}
catch
(...)
{
return
(
void
*
)
1
;
}
}
return
NULL
;
}
// Test that Signer and Verifier are thread safe.
TEST
(
ThreadSafetyTest
,
RunParallel
)
{
std
::
string
public_key
,
secret_key
;
sso
::
generate_keys
(
public_key
,
secret_key
);
sso
::
Signer
signer
(
secret_key
);
sso
::
Verifier
verifier
(
public_key
,
"service"
,
"domain"
);
TestContext
ctx
;
ctx
.
signer
=
&
signer
;
ctx
.
verifier
=
&
verifier
;
pthread_t
threads
[
NTHREADS
];
for
(
int
i
=
0
;
i
<
NTHREADS
;
i
++
)
{
pthread_create
(
&
threads
[
i
],
NULL
,
test_signer
,
&
ctx
);
}
for
(
int
i
=
0
;
i
<
NTHREADS
;
i
++
)
{
void
*
retval
;
pthread_join
(
threads
[
i
],
&
retval
);
EXPECT_EQ
(
NULL
,
retval
);
}
}
}
// namespace
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment