// DialWsClient_t.cxx #include "dial_ws/DialWsClient.h" #include #include #include #include "dataset_util/Text.h" #include "dataset_util/FileStatus.h" #include "dataset_util/pthread_sleep.h" #include "dial_ws/dial_ws_flags.h" using std::string; using std::cout; using std::endl; using std::ifstream; using dial::DialWsClient; #ifdef WITH_GSI #include "gsi.h" #endif void msg(string txt) { cout << "*** "; cout << txt; cout << " ***" << endl; } void sigpipe_handler(int) { cout << "Another broken pipe" << endl; } #ifdef WITH_GSI int client_authorization(struct soap* psoap) { struct gsi_plugin_data* pgsiplug = (struct gsi_plugin_data *) soap_lookup_plugin(psoap, GSI_PLUGIN_ID); //string client_identity = pgsiplug->client_identity; string service_identity = pgsiplug->server_identity; //cout << "GSI Client ID: " << client_identity << endl; cout << "GSI Service ID: " << service_identity << endl; return 0; } #endif int DialWsClient_t(bool usegsi) { signal(SIGPIPE, sigpipe_handler); if ( usegsi ) { msg("Testing with GSI"); } else { msg("Testing without GSI"); } #ifdef WITH_GSI if ( usegsi ) { // Create auth file. string globus_version = "3"; string gcom = "rm -f authorized_dn"; gcom += "; "; if ( globus_version == "2" ) { gcom += "grid-proxy-info -subject"; gcom += " | sed 's#/CN=proxy##g'"; } else { gcom += "grid-proxy-info -identity"; } gcom += " > authorized_dn"; system(gcom.c_str()); } #endif int pid = -1; if ( FileStatus("pid").exists() ) { msg("Clean up from earlier test"); ifstream pidfile("pid"); pidfile >> pid; if ( pid > 0 ) { cout << "Killing process " << pid << endl; kill(pid, SIGKILL); } unlink("pid"); pid = -1; sleep(1); // Give system time to free up port } msg("Start server"); assert( ! FileStatus("pid").exists() ); string com = "rm -rf server.log; "; com += "dialws base 8080 server.log "; if ( usegsi ) { com += "gsi"; } else { com += "none"; } com += " service"; com += " 1>stdout.log 2>&1 &"; cout << com << endl; int sysstat = system(com.c_str()); assert( sysstat == 0 ); for ( int i=0; i<35; ++i ) { cout << "."; if ( FileStatus("pid").exists() ) break; sleep(1); } cout << endl; assert( FileStatus("pid").exists() ); msg("Set server URL"); string server = "http://127.0.0.1:8080"; msg("Check server process"); int nloop = 0; while ( nloop < 10 ) { if ( FileStatus("pid").exists() ) break; sleep(1); ++nloop; } assert( nloop < 10 ); { ifstream pidfile("pid"); pidfile >> pid; } cout << "Server process ID is " << pid << endl; assert( pid > 0 ); sleep(1); msg("Create client"); DialWsClient client(server, usegsi); cout << server << endl; cout << usegsi << endl; msg("Check validity"); assert( client.is_valid() ); msg("Check server DN for WsClient"); Text audn("authorized_dn"); string sdn = audn.line(0); assert( sdn.size() ); cout << sdn << endl; if ( usegsi ) { assert( client.server_dn().size() ); cout << client.server_dn() << endl; assert( client.server_dn() == sdn ); } else { assert( client.server_dn().size() == 0 ); } if ( usegsi ) { msg("Check delegation for WsClient"); assert( ! client.is_delegating() ); if ( usegsi ) { assert( client.set_delegation() == 0 ); assert( client.is_delegating() ); } else { assert( client.set_delegation() != 0 ); assert( ! client.is_delegating() ); } } msg("Terminate service."); client.terminate_service(); assert( ! client.is_valid() ); while ( nloop < 10 ) { cout << "."; if ( ! FileStatus("pid").exists() ) break; cout.flush(); pthread_sleep(1); ++nloop; } cout << endl; return 0; } #ifdef CTEST_MAIN int main() { int stat = DialWsClient_t(true); if ( stat != 0 ) return stat; return DialWsClient_t(false); } #endif