Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,22 @@ add_test(
COMMAND
${CMAKE_CURRENT_BINARY_DIR}/scitokens-gtest
)


#
# Simple, interactive test of the asynchronous interface. Requires
# network access to do anything meaningful.
#
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}/asynch.py
)
124 changes: 124 additions & 0 deletions test/asynch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <stdio.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
#include <stdio.h>
#include "../src/scitokens.h"

#include <errno.h>
#include <stdlib.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>

#include <sys/select.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
#include <sys/select.h>

#include <string.h>
#include <unistd.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
#include <unistd.h>
#include <sys/select.h>
#include <unistd.h>

#include <errno.h>
#include "../src/scitokens.h"
Comment on lines +7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
#include <errno.h>
#include "../src/scitokens.h"


void
usage( const char * self ) {
fprintf( stderr, "usage: %s encoded-scitoken\n", self );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
void
usage( const char * self ) {
fprintf( stderr, "usage: %s encoded-scitoken\n", self );
void usage(const char *self) {
fprintf(stderr, "usage: %s encoded-scitoken\n", self);

}

void
void print_claim(SciToken &token, const char *claim) {
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
void
void print_claim(SciToken &token, const char *claim) {
void void print_claim(SciToken &token, const char *claim) {

char *value;
char *error;
int rv = scitoken_get_claim_string(token, claim, &value, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_get_claim_string('%s') failed: %s\n", claim,
error);
return;
}
fprintf( stdout, "%s = %s\n", claim, value );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
fprintf( stdout, "%s = %s\n", claim, value );
fprintf(stdout, "%s = %s\n", claim, value);

}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change

int main(int argc, char **argv) {
if (argc < 2) {
usage(argv[0]);
exit(-1);
}
const char *encoded = argv[1];
int rv;
char * error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
char * error;
char *error;

SciToken token;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change

// 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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
if( getcwd(cache_path, sizeof(cache_path)) == NULL ) {
fprintf( stderr, "Failed to determine cwd, aborting.\n" );
exit( -5 );
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, "Failed to set %s: %s, aborting.\n", key, cache_path );
exit( -5 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

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

}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change

// Asynchronous API.
SciTokenStatus status;
rv = scitoken_deserialize_start(
encoded, & token, NULL, & status, & error
);
if( rv != 0 ) {
fprintf( stderr, "scitoken_deserialize_start() failed: %s\n", error );
exit( -2 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
rv = scitoken_deserialize_start(
encoded, & token, NULL, & status, & error
);
if( rv != 0 ) {
fprintf( stderr, "scitoken_deserialize_start() failed: %s\n", error );
exit( -2 );
rv = scitoken_deserialize_start(encoded, &token, NULL, &status, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_deserialize_start() failed: %s\n", error);
exit(-2);

}
if( status == NULL ) {
fprintf( stderr, "scitoken_deserialize_start() returned a token\n" );
exit( 1 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
if( status == NULL ) {
fprintf( stderr, "scitoken_deserialize_start() returned a token\n" );
exit( 1 );
if (status == NULL) {
fprintf(stderr, "scitoken_deserialize_start() returned a token\n");
exit(1);

}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change

do {
fd_set * read_fds = NULL;
rv = scitoken_status_get_read_fd_set( & status, & read_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_read_fd_set() failed: %s\n", error );
exit( -2 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
fd_set * read_fds = NULL;
rv = scitoken_status_get_read_fd_set( & status, & read_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_read_fd_set() failed: %s\n", error );
exit( -2 );
fd_set *read_fds = NULL;
rv = scitoken_status_get_read_fd_set(&status, &read_fds, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_status_get_read_fd_set() failed: %s\n",
error);
exit(-2);

}

fd_set * write_fds = NULL;
rv = scitoken_status_get_write_fd_set( & status, & write_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_write_fd_set() failed: %s\n", error );
exit( -2 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
fd_set * write_fds = NULL;
rv = scitoken_status_get_write_fd_set( & status, & write_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_write_fd_set() failed: %s\n", error );
exit( -2 );
fd_set *write_fds = NULL;
rv = scitoken_status_get_write_fd_set(&status, &write_fds, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_status_get_write_fd_set() failed: %s\n",
error);
exit(-2);

}

fd_set * except_fds = NULL;
rv = scitoken_status_get_exc_fd_set( & status, & except_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_exc_fd_set() failed: %s\n", error );
exit( -2 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
fd_set * except_fds = NULL;
rv = scitoken_status_get_exc_fd_set( & status, & except_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_exc_fd_set() failed: %s\n", error );
exit( -2 );
fd_set *except_fds = NULL;
rv = scitoken_status_get_exc_fd_set(&status, &except_fds, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_status_get_exc_fd_set() failed: %s\n",
error);
exit(-2);

}

int max_fds;
rv = scitoken_status_get_max_fd( & status, & max_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_max_fds() failed: %s\n", error );
exit( -2 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
rv = scitoken_status_get_max_fd( & status, & max_fds, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_status_get_max_fds() failed: %s\n", error );
exit( -2 );
rv = scitoken_status_get_max_fd(&status, &max_fds, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_status_get_max_fds() failed: %s\n",
error);
exit(-2);

}

struct timeval time_out{1, 0};
int s = select( max_fds + 1, read_fds, write_fds, except_fds, & time_out );
if( s == -1 ) {
fprintf( stderr, "select() failed: %s (%d)\n", strerror(errno), errno );
exit( -4 );
} else if( s == 0 ) {
fprintf( stderr, "select() timed out, checking for progress.\n" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
struct timeval time_out{1, 0};
int s = select( max_fds + 1, read_fds, write_fds, except_fds, & time_out );
if( s == -1 ) {
fprintf( stderr, "select() failed: %s (%d)\n", strerror(errno), errno );
exit( -4 );
} else if( s == 0 ) {
fprintf( stderr, "select() timed out, checking for progress.\n" );
struct timeval time_out {
1, 0
};
int s = select(max_fds + 1, read_fds, write_fds, except_fds, &time_out);
if (s == -1) {
fprintf(stderr, "select() failed: %s (%d)\n", strerror(errno),
errno);
exit(-4);
} else if (s == 0) {
fprintf(stderr, "select() timed out, checking for progress.\n");

}

fprintf( stderr, "Calling scitoken_deserialize_continue()...\n" );
rv = scitoken_deserialize_continue( & token, & status, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_deserialize_continue() failed: %s\n", error );
exit( -3 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
fprintf( stderr, "Calling scitoken_deserialize_continue()...\n" );
rv = scitoken_deserialize_continue( & token, & status, & error );
if( rv != 0 ) {
fprintf( stderr, "scitoken_deserialize_continue() failed: %s\n", error );
exit( -3 );
fprintf(stderr, "Calling scitoken_deserialize_continue()...\n");
rv = scitoken_deserialize_continue(&token, &status, &error);
if (rv != 0) {
fprintf(stderr, "scitoken_deserialize_continue() failed: %s\n",
error);
exit(-3);

}
} while( status != NULL );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
} while( status != NULL );
} while (status != NULL);


print_claim(token, "ver");
print_claim(token, "aud");
print_claim(token, "iss");
print_claim(token, "jti");

scitoken_destroy( token );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[lint] reported by reviewdog 🐶

Suggested change
scitoken_destroy( token );
scitoken_destroy(token);

return 0;
}
38 changes: 38 additions & 0 deletions test/asynch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

import os
import json
import requests
import subprocess
import sys


def get_demo_token(payload: dict):
data = json.dumps({'algorithm': "ES256", 'payload': payload})
resp = requests.post("https://demo.scitokens.org/issue", data=data)
return resp.text


demo_payload = {
"ver": "scitoken:2.0",
"aud": "https://demo.scitokens.org",
"iss": "https://demo.scitokens.org",
}
demo_token = get_demo_token(demo_payload)

try:
scitokens_cache = f"{os.getcwd()}/scitokens/scitokens_cpp.sqllite"
os.unlink(scitokens_cache)
except FileNotFoundError:
pass

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

print(rv.stdout)
sys.exit(rv.returncode)