// FileGsiAuthorizer_t.cxx #include "dial_gsi/FileGsiAuthorizer.h" #include "dataset_util/DtdRegistry.h" #include "dataset_util/FileName.h" #include "dataset_util/XmlElement.h" #include #include using std::string; using std::cout; using std::endl; using dial::FileGsiAuthorizer; namespace { void msg(string msg) { cout << "----- "; cout << msg; cout << " -----" << endl; } } // end unnamed namespace int FileGsiAuthorizer_t() { msg("Begin testing GsiAuthorizer"); system("rm -f users"); Text t("users"); t.append(" \"abc123\" abc "); t.append("def234 "); t.append("this is my DN"); t.append("#ghi345 ghi"); t.append("\"jkl456\" jkl"); t.write(); msg("Create FileGsiAuthorizer object"); FileGsiAuthorizer fgsiauth(t.name()); cout << fgsiauth << endl; msg("Check authorization"); assert( fgsiauth.is_authorized("abc123") ); msg("Check authorization"); assert( fgsiauth.is_authorized("def234") ); msg("Check authorization with spaces"); assert( ! fgsiauth.is_authorized("this") ); assert( fgsiauth.is_authorized("this is my DN") ); msg("Check authorization denied"); assert( ! fgsiauth.is_authorized("ghi345") ); msg("Check authorization denied"); assert( fgsiauth.is_authorized("abc123") ); assert( ! fgsiauth.is_authorized_with_role("abc123", "Admin") ); msg("Check update"); t.append("mno567 mno"); t.write(); assert( fgsiauth.update() == 0 ); assert( fgsiauth.is_authorized("mno567 mno")); msg("Write to XML"); const XmlElement* pele = fgsiauth.xml(); assert(pele != 0); cout << *pele << endl; msg("Read from XML"); FileGsiAuthorizer fgsi(*pele); cout << fgsi << endl; delete pele; msg("Check DTD"); cout << FileGsiAuthorizer::dtd() << endl; assert( FileGsiAuthorizer::dtd().size() != 0 ); assert( DtdRegistry::instance("dial").has_type("FileGsiAuthorizer") ); msg("All tests passed."); return 0; } #ifdef CTEST_MAIN int main() { return FileGsiAuthorizer_t(); } #endif