def createEmailtestApp(klass): name = klass.createRandomUserId() app = Application.new(name, name, "https://{0}.com/".format(name)) klass.allApps.add(app) AppMap.new(app, klass.user) klass.boundApps.add(app) klass.app = app
def _getDeregistrationSecret(self): self._loginAndDeregister() user = self.cred.user if self.addAppMapToUser == True: app = Application.query.first() # @UndefinedVariable AppMap.new(app, user) deregistrationCredential = Credential.getByUser(user, 'deregister') secret = deregistrationCredential.secret return secret
def _getDeregistrationSecret(self): self._loginAndDeregister() user = self.cred.user if self.addAppMapToUser==True: app = Application.query.first() # @UndefinedVariable AppMap.new(app, user) deregistrationCredential = Credential.getByUser(user, 'deregister') secret = deregistrationCredential.secret return secret
def test_in_hash_collision_if_the_other_user_is_hand_assured_the_user_is_not_deleted(self): anotheruser = self.createUserWithCredentials().user digest = self.createHash() anotheruser.hash = digest Assurance.new(anotheruser, "test", anotheruser) anotheruser.save() user = self.createUserWithCredentials().user app = Application.query.first() # @UndefinedVariable AppMap.new(app, user) email = self.userCreationEmail additionalInfo = dict() with self.assertRaises(ReportedError): self.controller.checkHashInOtherUsers(user,additionalInfo,digest) self.assertEqual(email, User.getByEmail(email).email)
def setCanEmail(self, appName, user, value): app = Application.find(appName) if app == None: raise ReportedError(Messages.unknownApplication) theMap = AppMap.get(app, user) theMap.can_email = value theMap.save()
def test_the_list_of_applications_contain_all_applications_for_the_user( self): userMaps = AppMap.getForUser(self.user) appList = set() for appMap in userMaps: appList.add(appMap.app) self.assertEqual(self.boundApps, appList)
def test_proxy_id_is_not_created_deterministically(self): cred = self.createLoggedInUser() app = self.app mapentry = AppMap(app, cred.user) mapentry.save() oldid = mapentry.userid mapentry.rm(); mapentry = AppMap(app, cred.user) self.assertNotEqual(oldid, mapentry.userid)
def test_the_email_address_shown_for_the_user_is_userid_dot_appname_at_EMAILDOMAIN( self): userinfo1 = self.getUserInfo() appMapEntry = AppMap.get(self.app, self.cred.user) emailAddress = "{0}.{1}@{2}".format(appMapEntry.userid, self.app.name, config.Config.EMAIL_DOMAIN) self.assertEqual(userinfo1['email'], emailAddress) self.assertEqual(userinfo1['email'], appMapEntry.getEmail())
def removeFbuser(self, user=None): if user is None: user = config.facebookUser2 self.user = User.getByEmail(user.email) if self.user: Credential.getByUser(self.user, "facebook").rm() for appMap in AppMap.getForUser(self.user): appMap.rm() self.user.rm()
def test_the_email_address_shown_for_the_user_is_userid_dot_appname_at_EMAILDOMAIN(self): userinfo1 = self.getUserInfo() appMapEntry = AppMap.get(self.app, self.cred.user) emailAddress = "{0}.{1}@{2}".format( appMapEntry.userid, self.app.name, config.Config.EMAIL_DOMAIN) self.assertEqual(userinfo1['email'], emailAddress) self.assertEqual(userinfo1['email'], appMapEntry.getEmail())
def removeFbuser(self,user=None): if user is None: user = config.facebookUser2 self.user = User.getByEmail(user.email) if self.user: Credential.getByUser(self.user, "facebook").rm() for appMap in AppMap.getForUser(self.user): appMap.rm() self.user.rm()
def shownDataForApp(self, user, authenticator): app = Application.get(authenticator) appmapEntry = AppMap.get(app, user) shownEmail = appmapEntry.getEmail() shownUserId = appmapEntry.userid shownAssurances = self.computeAssurancesForApp(user, app) return dict( email=shownEmail, userid=shownUserId, assurances=shownAssurances)
def test_the_server_can_get_your_user_info_with_your_access_token(self): accessToken = self.obtainAccessToken()['access_token'] url = TE.backendUrl + "/v1/users/me" headers = {'Authorization': 'Bearer {0}'.format(accessToken)} resp = requests.get(url, headers=headers, verify=False) answer = resp.json() user = User.getByEmail(self.userCreationEmail) appMapEntry = AppMap.get(TE.app, user) self.assertEqual(answer['email'], appMapEntry.getEmail()) self.assertEqual(answer['assurances'], [])
def test_the_list_entries_contain_whether_the_user_enabled_emailing(self): missingCount = 0 for entry in self.appList: app = Application.find(entry['name']) mapEntry = AppMap.find(app, self.user) if mapEntry: self.assertEqual(entry['email_enabled'], mapEntry.can_email) else: missingCount += 1 self.assertTrue(missingCount < len(self.appList)) self.assertTrue(missingCount > 0)
def assertUserSetTheMap(self, app, theCase, theString): with app.test_client() as c: theApp = self.chooseAppWithOppositeEmailCapability(theCase) self.login(c, self.user) csrf = self.getCSRF(c) data = dict(csrf_token=csrf, appname=theApp.name, canemail=theString) resp = c.post("/v1/setappcanemail", data=data) self.assertEqual('200 OK', resp.status) self.assertEqual(theCase, AppMap.get(theApp, self.user).can_email)
def test_the_list_entries_contain_whether_the_user_enabled_emailing(self): missingCount= 0 for entry in self.appList: app = Application.find(entry['name']) mapEntry=AppMap.find(app,self.user) if mapEntry: self.assertEqual(entry['email_enabled'], mapEntry.can_email) else: missingCount += 1 self.assertTrue(missingCount < len(self.appList)) self.assertTrue(missingCount > 0)
def createUserAppMapEntry(self, user, app): entry = dict(name=app.name, can_email=app.can_email, hostname=app.redirect_uri.split('/')[2]) appMapEntry = AppMap.find(app, user) if appMapEntry: entry['email_enabled'] = appMapEntry.can_email entry['username'] = appMapEntry.userid else: entry['email_enabled'] = None entry['username'] = None return entry
def createTestAppMaps(self): self.boundApps = set() self.emailerApps = list() for i in range(20): # @UnusedVariable name = self.createRandomUserId() newApp = Application.new(name, name, "https://{0}.com/".format(name)) if (random.randint(1, 2) == 1): newApp.can_email = True newApp.save() self.emailerApps.append(newApp) self.allApps = set(Application.all()) self.emailerMaps = list() for app in self.allApps: if (random.randint(1, 2) == 1): self.boundApps.add(app) m = AppMap.new(app, self.user) if app.can_email and (random.randint(1, 2) == 1): m.can_email = True self.emailerMaps.append(m) m.save()
def test_the_user_can_unset_the_can_email_attribute_of_the_app_map(self): boundApp = self.emailerApps[0] theMap = AppMap.get(boundApp, self.user) theMap.can_email = True self.appHandler.setCanEmail(boundApp.name, self.user, False) self.assertEqual(theMap.can_email, False)
def test_the_list_of_applications_contain_all_applications_for_the_user(self): userMaps = AppMap.getForUser(self.user) appList = set() for appMap in userMaps: appList.add(appMap.app) self.assertEqual(self.boundApps,appList)
def test_appMap_can_email_is_false_even_if_the_app_can_email(self): appMap = AppMap.new(self.app,self.user) self.emailerApps.append(self.app) self.assertEqual(False,appMap.can_email)
def test_appMap_can_email_is_false_by_default(self): appMap = AppMap.new(self.app,self.user) self.assertEqual(False,appMap.can_email)
def test_appMap_can_email_is_false_even_if_the_app_can_email(self): appMap = AppMap.new(self.app, self.user) self.emailerApps.append(self.app) self.assertEqual(False, appMap.can_email)
def removeAppMaps(self, user): for appmap in AppMap.getForUser(user): appmap.rm()
def test_the_list_entries_contain_the_proxy_username(self): for entry in self.appList: app = Application.find(entry['name']) mapEntry = AppMap.find(app, self.user) if mapEntry: self.assertEqual(entry['username'], mapEntry.userid)
def test_the_list_entries_contain_the_proxy_username(self): for entry in self.appList: app = Application.find(entry['name']) mapEntry=AppMap.find(app,self.user) if mapEntry: self.assertEqual(entry['username'], mapEntry.userid)
def chooseAppWithOppositeEmailCapability(self, canEmail): for appName in self.appNames: theApp = Application.find(appName) theMap = AppMap.get(theApp, self.user) if theMap.can_email is not canEmail: return theApp
def test_appMap_can_email_is_false_by_default(self): appMap = AppMap.new(self.app, self.user) self.assertEqual(False, appMap.can_email)