// GssCredential_t.cxx #include #include #include "dataset_util/Text.h" #include "dataset_util/FileStatus.h" #include "dataset_credential/GssCredential.h" using std::string; using std::cout; using std::endl; using dset::GssCredential; void msg(string txt) { cout << "*** "; cout << txt; cout << " ***" << endl; } int GssCredential_t() { msg("Create credential"); GssCredential* pcred = new GssCredential; GssCredential& cred = *pcred; cout << cred << endl; assert( cred.is_valid() ); assert( cred.manage() ); assert( cred.gss_handle() != 0 ); assert( cred.file().size() == 0 ); assert( cred.error_message().size() == 0 ); msg("Check the name"); string name1 = cred.name(); cout << name1 << endl; assert( name1.size() ); msg("Check the time reamaining"); int time = cred.timeleft(); cout << time << endl; assert( time > 0 ); msg("Export credential"); assert( cred.export_to_file() == 0 ); string file1 = cred.file(); assert( file1.size() != 0 ); cout << file1 << endl; assert( cred.error_message().size() == 0 ); msg("Delete credential file"); assert( cred.file().size() != 0 ); assert( FileStatus(file1).exists() ); assert( cred.delete_file() == 0 ); assert( ! FileStatus(file1).exists() ); assert( cred.file().size() == 0 ); msg("Copy credential shallow"); GssCredential cred1 = cred; assert( cred1.is_valid() ); assert( ! cred1.manage() ); assert( cred1.file().size() == 0 ); assert( cred1.error_message().size() == 0 ); assert( cred1.gss_handle() != 0 ); assert( cred1.gss_handle() == cred.gss_handle() ); assert( cred1.name() == cred.name() ); msg("Copy credential deep"); GssCredential* pcred2 = new GssCredential(cred, true); GssCredential& cred2 = *pcred2; assert( cred2.is_valid() ); assert( cred2.manage() ); assert( cred2.file().size() == 0 ); assert( cred2.error_message().size() == 0 ); assert( cred2.gss_handle() != 0 ); assert( cred2.gss_handle() != cred.gss_handle() ); assert( cred2.name() == cred.name() ); msg("Export copied credential"); assert( cred2.export_to_file() == 0 ); string file2 = cred2.file(); assert( file2.size() != 0 ); cout << file2 << endl; assert( file2 != file1 ); msg("Check credential file management"); assert( FileStatus(file2).exists() ); delete pcred; assert( FileStatus(file2).exists() ); delete pcred2; assert( ! FileStatus(file2).exists() ); msg("Extract GSS credential"); GssCredential cred3; cout << cred3 << endl; assert( cred3.is_valid() ); gss_cred_id_t pgss3 = cred3.gss_handle(); assert( pgss3 != 0 ); msg("Construct reference credential from GSS credential"); GssCredential cred4(pgss3); cout << cred4 << endl; assert( cred4.is_valid() ); assert( ! cred4.manage() ); assert( cred4.gss_handle() == pgss3 ); msg("Construct new credential from GSS credential"); GssCredential cred5(pgss3, true); cout << cred5 << endl; assert( cred5.is_valid() ); assert( cred5.manage() ); assert( cred5.gss_handle() != 0 ); assert( cred5.gss_handle() != pgss3 ); return 0; } #ifdef CTEST_MAIN int main() { return GssCredential_t(); } #endif