Skip to content

Commit

Permalink
Add a script to automatically drive the asynch C code; don't use the …
Browse files Browse the repository at this point in the history
…user's key cache.
  • Loading branch information
Todd-L-Miller committed Sep 15, 2023
1 parent 141b29c commit e9098de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ add_test(
add_executable( scitokens-asynch-test asynch.cc )
target_link_libraries( scitokens-asynch-test SciTokens )

# This can't be the right to do specify this, and it also doesn't
# handle aysnch.py being updated correctly.
file(COPY asynch.py DESTINATION ${CMAKE_BINARY_DIR}/test)

add_test(
NAME
asynch
COMMAND
${CMAKE_CURRENT_BINARY_DIR}/scitokens-asynch-test
${CMAKE_CURRENT_BINARY_DIR}/asynch.py
)
29 changes: 12 additions & 17 deletions test/asynch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ main( int argc, char ** argv) {
char * error;
SciToken token;

/*
// Synchronous.
rv = scitoken_deserialize( encoded, & token, NULL, & error );

// Set the cache to the CWD while testing.
char cache_path[FILENAME_MAX];
if( getcwd(cache_path, sizeof(cache_path)) == NULL ) {
fprintf( stderr, "Failed to determine cwd, aborting.\n" );
exit( -5 );
}

const char * key = "keycache.cache_home";
rv = scitoken_config_set_str( key, cache_path, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_deserialize() failed: %s\n", error );
exit( -2 );
fprintf( stderr, "Failed to set %s: %s, aborting.\n", key, cache_path );
exit( -5 );
}
// scitoken_destroy( token );
*/

// The asynchronous API doesn't work like the synchronous API, and
// requires that deserialization profile be set before it starts
// working. This is probably a bug, but there's another bug where
// the default value for the profile causes a throw. *sigh*

// Asynchronous API.
SciTokenStatus status;
Expand Down Expand Up @@ -117,12 +118,6 @@ main( int argc, char ** argv) {
print_claim(token, "ver");
print_claim(token, "aud");
print_claim(token, "iss");
// Not a string.
// print_claim(token, "exp");
// Not a string.
// print_claim(token, "iat");
// Not a string.
// print_claim(token, "nbf");
print_claim(token, "jti");

scitoken_destroy( token );
Expand Down
6 changes: 2 additions & 4 deletions test/asynch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ def get_demo_token(payload: dict):
demo_token = get_demo_token(demo_payload)

try:
scitokens_cache = os.path.expanduser('~/.cache/scitokens/scitokens_cpp.sqllite')
scitokens_cache = f"{os.getcwd()}/scitokens/scitokens_cpp.sqllite"
os.unlink(scitokens_cache)
except OSError:
pass
except FileNotFoundError:
pass

rv = subprocess.run(
['test/scitokens-asynch-test', demo_token],
['./scitokens-asynch-test', demo_token],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=5,
Expand Down

0 comments on commit e9098de

Please sign in to comment.