// WsClient_t.cxx #include "dial_ws/WsClient.h" #include #include #include #include "dataset_util/FileStatus.h" #include "dial_ws/dial_ws_flags.h" using std::string; using std::cout; using std::endl; using std::ifstream; using dial::WsClient; #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 WsClient_t(bool usegsi) { signal(SIGPIPE, sigpipe_handler); #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 gsi service &"; 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 = "https://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 ); msg("Create client"); WsClient client(server, usegsi); msg("Check validity"); assert( client.is_valid() ); msg("Check timeout"); cout << client.timeout() << endl; client.set_timeout(10); cout << client.timeout() << endl; assert( client.timeout() == 10 ); msg("Check server DN done in DialWsClient"); msg("Check delegation done in DialWsClient"); msg("Terminate service."); system("ps"); system("kill `cat pid`"); sleep(1); system("ps"); return 0; } #ifdef CTEST_MAIN int main() { int stat = WsClient_t(true); if ( stat != 0 ) return stat; return WsClient_t(false); } #endif