def setUp(self): self.user1 = User("Max Mustermann") self.user2 = User("12345") self.service1 = LoginService("MusterService", ["fileStorage"]) self.service2 = LoginService("BetonService", ["fileStorage"]) self.token1 = Token(self.user1, self.service1, "ABC") self.token2 = Token(self.user1, self.service2, "DEF") self.oauthservice1 = OAuth2Service( "MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://localhost/oauth/authorize", "http://localhost/oauth/token", "MNO", "UVW", ) self.oauthservice2 = OAuth2Service( "BetonService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://owncloud/oauth/authorize", "http://owncloud/oauth/token", "UVP", "OMN", ) self.oauthtoken1 = OAuth2Token(self.user1, self.oauthservice1, "ABC", "XYZ") self.oauthtoken2 = OAuth2Token(self.user1, self.oauthservice2, "DEF", "UVW")
def setUp(self): self.service1 = LoginService("MusterService", ["fileStorage"]) self.service2 = LoginService("BetonService", ["fileStorage"]) self.oauthservice1 = OAuth2Service.from_service( self.service1, "http://localhost:5000/oauth/authorize", "http://localhost:5000/oauth/refresh", "ABC", "XYZ", ) self.oauthservice2 = OAuth2Service.from_service( self.service2, "http://localhost:5000/oauth/authorize", "http://localhost:5000/oauth/refresh", "DEF", "MNO", ) self.user1 = User("Max Mustermann") self.user2 = User("Mimi Mimikri") self.token1 = Token(self.user1, self.service1, "ABC") self.token2 = Token(self.user1, self.service2, "DEF") self.oauthtoken1 = OAuth2Token(self.user1, self.oauthservice1, "ABC", "XYZ") self.oauthtoken2 = OAuth2Token(self.user1, self.oauthservice2, "DEF", "UVW")
def setUp(self): Util.monkeypatch() self.empty_storage = Storage(**get_opts()) self.user1 = User("Max Mustermann") self.user2 = User("Mimi Mimikri") self.service1 = LoginService(servicename="MusterService", implements=["metadata"]) self.service2 = LoginService(servicename="FahrService", implements=["metadata"]) self.oauthservice1 = OAuth2Service( servicename="BetonService", implements=["metadata"], authorize_url="http://localhost/oauth/authorize", refresh_url="http://localhost/oauth/token", client_id="MNO", client_secret="UVW", ) self.oauthservice2 = OAuth2Service( servicename="FlugService", implements=["metadata"], authorize_url="http://localhost21/oauth/authorize", refresh_url="http://localhost21/oauth/token", client_id="XCA", client_secret="BCXY", ) self.empty_storage.addService(self.service1) self.empty_storage.addService(self.oauthservice1) self.empty_storage.addService(self.oauthservice2) self.token1 = Token(self.user1, self.service1, "ABC") self.token_like_token1 = Token(self.user1, self.service1, "DEF") self.token2 = Token(self.user1, self.oauthservice1, "XYZ") self.token3 = Token(self.user2, self.service2, "XASD") self.token4 = Token(self.user2, self.service1, "IOAJSD") self.oauthtoken1 = OAuth2Token(self.user1, self.oauthservice1, "ABC", "X_ABC") self.oauthtoken_like_token1 = OAuth2Token(self.user1, self.oauthservice1, "ABC", "X_DEF") self.oauthtoken2 = OAuth2Token(self.user1, self.oauthservice1, "XYZ", "X_XYZ") self.oauthtoken3 = OAuth2Token(self.user1, self.oauthservice2, "XYZ", "X_XYZ")
def test_service_give_description(self): text = "This is a test description." svc1 = BaseService("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, text) self.assertEqual(svc1.description, text) self.assertNotEqual(svc1.description, "This is not valid.") self.assertEqual(svc1.to_dict().get("description"), text) self.assertEqual( BaseService.from_dict(svc1.to_dict()).description, text) self.assertEqual( BaseService.from_json(svc1.to_json()).description, text) svc1 = OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://localhost:5001", "http://localhost:5001/oauth/refresh", "ABC", "XYZ", text) self.assertEqual(svc1.description, text) svc1 = LoginService("Service", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, False, False, text) self.assertEqual(svc1.description, text)
def test_logintoken(self): user1 = User("Max Mustermann") user2 = User("12345") service1 = LoginService("MusterService", ["fileStorage"]) service2 = LoginService("BetonService", ["fileStorage"], userId=False) service3 = LoginService("FahrService", ["fileStorage"], password=False) service4 = LoginService("TaxiService", ["fileStorage"], userId=False, password=False) with self.assertRaises(ValueError): LoginToken(None, service1, "") with self.assertRaises(ValueError): LoginToken(user1, service1, "") with self.assertRaises(ValueError): LoginToken(None, service1, "DEF") with self.assertRaises(ValueError): LoginToken(None, service2, "") with self.assertRaises(ValueError): LoginToken(user1, service2, "") LoginToken(None, service2, "DEF") with self.assertRaises(ValueError): LoginToken(None, service3, "") LoginToken(user1, service3, "") LoginToken(user1, service3, None) LoginToken(user1, service3, "DEF") with self.assertRaises(ValueError): LoginToken(None, service3, "DEF") LoginToken(None, service4, None) LoginToken(None, service4, "") LoginToken(user1, service4, "") LoginToken(None, service4, "DEF") Token(user1, service1, "DEF") Token(user1, service3, "DEF")
def test_token_service_init(self): user1 = User("Max Mustermann") service1 = BaseService("MusterService", ["fileStorage"]) service2 = LoginService("BetonService", ["fileStorage"], userId=True, password=False) LoginToken(user1, service2, "") with self.assertRaises(ValueError): Token(user1, service1, "")
def test_parseToken(self): user1 = User("MaxMustermann") service1 = LoginService("MusterService", ["fileStorage"]) token1 = Token(user1, service1, "ABC") serviceport = "{}".format(token1.service.servicename) data = { "userId": "port-{}://{}:{}".format("musterservice", "MaxMustermann", "ABC") } self.assertEqual(Util.parseToken(token1), data)
def test_init_objects(self): self.assertEqual(Util.getServiceObject(json.dumps(self.oauthservice1)), self.oauthservice1) svc1 = LoginService("MusterService", ["fileStorage"]) self.assertEqual(Util.getServiceObject(json.dumps(svc1)), svc1) self.assertNotEqual( Util.getServiceObject(json.dumps(svc1)).__class__, self.oauthservice1.__class__) self.assertEqual(Util.getUserObject(json.dumps(self.user1)), self.user1) self.assertEqual(Util.getTokenObject(json.dumps(self.token1)), self.token1)
def test_tokenstorage_service_implementstype(self): empty_storage = Storage(**get_opts()) service = LoginService(servicename="longname", implements=["fileStorage", "metadata"]) empty_storage.addUser(self.user1) token1 = Token(self.user1, service, "ISADF") # test the exception raise with self.assertRaises(ServiceNotExistsError): empty_storage.addTokenToUser(token1, self.user1) # now should work self.assertTrue(empty_storage.addService(service)) self.assertTrue(empty_storage.addTokenToUser(token1, self.user1)) self.assertEqual(empty_storage.getTokens(self.user1), [token1]) with self.assertRaises(ServiceExistsAlreadyError): empty_storage.addService(service)
def test_implements(self): with self.assertRaises(ValueError): LoginService("", [], FileTransferMode.active, FileTransferArchive.none) with self.assertRaises(ValueError): LoginService("", ["not_working"], FileTransferMode.active, FileTransferArchive.none) with self.assertRaises(ValueError): LoginService("", ["metadata", "not_working"], FileTransferMode.active, FileTransferArchive.none) with self.assertRaises(ValueError): LoginService("", ["metadata", "fileStorage", "not_working"], FileTransferMode.active, FileTransferArchive.none) LoginService("TestService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none) LoginService("TestService", ["fileStorage", "metadata"], FileTransferMode.active, FileTransferArchive.none)
def test_service(self): with self.assertRaises(ValueError): LoginService("", [], FileTransferMode.active, FileTransferArchive.none, "", "") with self.assertRaises(ValueError): LoginService("Service", [], 3, "", False, False) with self.assertRaises(ValueError): LoginService("Service", ["not_working"], FileTransferMode.active, FileTransferArchive.none, False, False) with self.assertRaises(ValueError): LoginService("Service") LoginService("Service", ["fileStorage"]) LoginService("Service", ["fileStorage"], FileTransferMode.active) LoginService("Service", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none) LoginService("Service", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, False) LoginService("Service", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, True, False) LoginService("Service", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, False, False) with self.assertRaises(ValueError): OAuth2Service("", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "", "", "") with self.assertRaises(ValueError): OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "", "", "") with self.assertRaises(ValueError): OAuth2Service("", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://localhost:5001/oauth/authorize", "", "", "") with self.assertRaises(ValueError): OAuth2Service("", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "http://localhost:5001/oauth/refresh", "", "") with self.assertRaises(ValueError): OAuth2Service("", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "", "ABC", "") with self.assertRaises(ValueError): OAuth2Service("", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "", "", "XYZ") with self.assertRaises(ValueError): OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://localhost:5001/oauth/authorize", "", "", "") with self.assertRaises(ValueError): OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "http://localhost:5001/oauth/refresh", "", "") with self.assertRaises(ValueError): OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "", "ABC", "") with self.assertRaises(ValueError): OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "", "", "XYZ") with self.assertRaises(ValueError): OAuth2Service("MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://localhost:5001/oauth/refresh", "", "", "") with self.assertRaises(ValueError): OAuth2Service( "MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "http://localhost:5001/oauth/authorize", "http://localhost:5001/oauth/refresh", "", "", ) # same input for authorize and refresh with self.assertRaises(ValueError): OAuth2Service( "MusterService", ["fileStorage"], FileTransferMode.active, FileTransferArchive.none, "", "http://localhost:5001/oauth/authorize", "http://localhost:5001/oauth/refresh", "", "", )
def setUp(self): self.app = create_app() self.client = self.app.test_client() self.empty_storage = Storage() self.success = {"success": True} self.user1 = User("Max Mustermann") self.user2 = User("Mimi Mimikri") self.user3 = User("Karla Kolumda") self.service1 = LoginService(servicename="MusterService", implements=["metadata"]) self.service2 = LoginService(servicename="BetonService", implements=["metadata"]) self.service3 = LoginService(servicename="FahrService", implements=["metadata"]) self.oauthservice1 = OAuth2Service.from_service( self.service1, f"{pact_host_fqdn}/owncloud/index.php/apps/oauth2/authorize", f"{pact_host_fqdn}/owncloud/index.php/apps/oauth2/api/v1/token", "ABC", "XYZ", ) self.oauthservice2 = OAuth2Service.from_service( self.service2, f"{pact_host_fqdn}/oauth/authorize", f"{pact_host_fqdn}/oauth/token", "DEF", "UVW", ) self.oauthservice3 = OAuth2Service.from_service( self.service3, f"{pact_host_fqdn}/api/authorize", f"{pact_host_fqdn}/api/token", "GHI", "MNO", ) self.token1 = Token(self.user1, self.service1, "ABC") self.token_like_token1 = Token(self.user1, self.service1, "DEF") self.token2 = Token(self.user2, self.service2, "XYZ") self.token3 = Token(self.user1, self.service3, "GHI") self.oauthtoken1 = OAuth2Token(self.user1, self.oauthservice1, "ABC", "X_ABC") self.oauthtoken_like_token1 = OAuth2Token(self.user1, self.oauthservice1, "X_DEF") self.oauthtoken2 = OAuth2Token(self.user2, self.oauthservice2, "XYZ", "X_XYZ") self.oauthtoken3 = OAuth2Token(self.user1, self.oauthservice3, "GHI", "X_GHI") self.services = [ self.service1, self.service2, self.service3, self.oauthservice1, self.oauthservice2, self.oauthservice3, ] self.filled_storage_without_tokens = Storage() self.filled_storage_without_tokens.addUser(self.user1) self.filled_storage_without_tokens.addUser(self.user2) self.filled_storage_without_tokens.addUser(self.user3) self.filled_storage = Storage() self.filled_storage.addService(self.oauthservice1) self.filled_storage.addService(self.oauthservice2) self.filled_storage.addService(self.oauthservice3) # user1 is filled with mixed token and oauth2token self.filled_storage.addUser(self.user1) self.filled_storage.addTokenToUser(self.token1, self.user1) self.filled_storage.addTokenToUser(self.token3, self.user1) self.filled_storage.addTokenToUser(self.oauthtoken1, self.user1, Force=True) # user2 is only filled with token self.filled_storage.addUser(self.user2) self.filled_storage.addTokenToUser(self.token2, self.user2)
#!/usr/bin/env python from __init__ import app, register_service import os from RDS import Util, LoginService, FileTransferMode, FileTransferArchive service = LoginService( servicename="port-datasafe", implements=["metadata"], fileTransferMode=FileTransferMode.passive, fileTransferArchive=FileTransferArchive.none, userId=False, password=False, description={"en": "datasafe is a service of WWU Münster for archiving research data. With the help of datasafe, you can enrich your research data with descriptive metadata and archive the resulting dataset for ten years on WWU servers.", "de": "datasafe ist ein Service der WWU Münster zum Archivieren von Forschungsdaten. Mit Hilfe von datasafe können Sie ihre Forschungsdaten mit beschreibenden Metadaten anreichern und den resultierenden Datensatz für zehn Jahre auf Servern der WWU archivieren."}, infoUrl="https://datasafe-dev.uni-muenster.de/", helpUrl="https://datasafe-dev.uni-muenster.de/datasafe/frequently_asked_questions", icon="./datasafe.svg", displayName="Datasafe", ) Util.register_service(service) # set the WSGI application callable to allow using uWSGI: # uwsgi --http :8080 -w app app.run(port=8080, server="gevent")