示例#1
0
 def testIsDeveloper(self):
     with test_utils.EnvContext(SERVER_SOFTWARE='Google App Engine/1.7.6'):
         self.assertFalse(users.IsDeveloper())
         with test_utils.EnvContext(USER_IS_ADMIN='1'):
             self.assertTrue(users.IsDeveloper())
     with test_utils.EnvContext(SERVER_SOFTWARE='Development/1.0'):
         self.assertTrue(users.IsDeveloper())
示例#2
0
 def testGetCurrent_AfterGetForEmailWithNonexistentGoogleAccount(self):
   self.mox.stubs.Set(users, '_EmailToGaeUserId', {}.get)
   # Introduce a previously unseen e-mail address.
   self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
   # A sign-in with that e-mail address should associate the Google Account.
   with test_utils.EnvContext(USER_ID='123456789', USER_EMAIL='*****@*****.**'):
     self.assertEquals('1', users.GetCurrent().id)
   # Subsequent sign-ins with the same Google Account ID should also hook up.
   with test_utils.EnvContext(USER_ID='123456789',
                              USER_EMAIL='*****@*****.**'):
     self.assertEquals('1', users.GetCurrent().id)
示例#3
0
 def testGetCurrent_GoogleAccountMapping(self):
     with test_utils.EnvContext(USER_ID='123456789',
                                USER_EMAIL='*****@*****.**'):
         user = users.GetCurrent()  # should allocate the first uid, '1'
         self.assertEquals('1', user.id)
     with test_utils.EnvContext(USER_ID='666666',
                                USER_EMAIL='*****@*****.**'):
         user = users.GetCurrent()  # should allocate the next uid, '2'
         self.assertEquals('2', user.id)
     with test_utils.EnvContext(USER_ID='123456789',
                                USER_EMAIL='*****@*****.**'):
         user = users.GetCurrent()  # should match by USER_ID
         self.assertEquals('1', user.id)
示例#4
0
 def testGetCurrent_UpdateEmailAndDomain(self):
     with test_utils.EnvContext(USER_ID='123456789',
                                USER_EMAIL='*****@*****.**',
                                USER_ORGANIZATION='alpha.test'):
         users.GetCurrent()  # should allocate the first uid, '1'
         user = users.Get('1')
         self.assertEquals('alpha.test', user.ga_domain)
         self.assertEquals('*****@*****.**', user.email)
     with test_utils.EnvContext(USER_ID='123456789',
                                USER_EMAIL='*****@*****.**',
                                USER_ORGANIZATION='beta.test'):
         users.GetCurrent()  # should update the existing UserModel
         user = users.Get('1')
         self.assertEquals('beta.test', user.ga_domain)
         self.assertEquals('*****@*****.**', user.email)
示例#5
0
    def testLoggedInSingleReportWithNoAnswers(self):
        with test_utils.EnvContext(USER_ID='123456789',
                                   USER_EMAIL='*****@*****.**',
                                   USER_ORGANIZATION='alpha.test'):
            self.DoPost(
                '/.api/reports', {
                    'cm-topic-ids': 'foo,bar',
                    'cm-answers-json': '',
                    'cm-text': 'report1',
                    'xsrf_token': 'XSRF'
                })  # XSRF check is stubbed in test_utils

        response = self.DoGet('/.api/reports?topic_ids=foo')

        reports = json.loads(response.body)
        self.assertEquals(1, len(reports))
        id0 = reports[0].pop('id')
        self.assertTrue(id0.startswith('http://app.com/root/.reports/'))
        self.assertDictEqual(
            {
                u'answers': {},
                u'source': u'http://app.com/root',
                u'author': u'http://app.com/root/.users/1',
                u'author_email': u'*****@*****.**',
                u'effective': self.default_time_secs,
                u'location': [model.NOWHERE.lat, model.NOWHERE.lon],
                u'place_id': None,
                u'submitted': self.default_time_secs,
                u'topic_ids': [u'foo', u'bar'],
                u'text': u'report1',
                u'updated': self.default_time_secs,
                u'upvote_count': 0,
                u'downvote_count': 0
            }, reports[0])
示例#6
0
 def testGetCurrent_NormalLogin(self):
     # Try an effective user determined by the Google Account login.
     with test_utils.EnvContext(USER_ID='123456789',
                                USER_EMAIL='*****@*****.**',
                                USER_ORGANIZATION='alpha.test'):
         user = users.GetCurrent()  # should allocate the first uid, '1'
         self.assertEquals('1', user.id)
         user = users.Get('1')
         self.assertEquals('alpha.test', user.ga_domain)
         self.assertEquals('*****@*****.**', user.email)
示例#7
0
 def testGetCurrent_ImpersonationNotAllowed(self):
   # Verify that the crisismap_login cookie doesn't work for ordinary users.
   with test_utils.EnvContext(
       SERVER_SOFTWARE='Google App Engine/1.7.6', USER_ID='123456789',
       USER_EMAIL='*****@*****.**', USER_ORGANIZATION='alpha.test',
       HTTP_COOKIE='crisismap_login=t1000:sky.net:[email protected]'):
     user = users.GetCurrent()
     self.assertEquals('1', user.id)  # cookie should be ignored
     self.assertEquals('alpha.test', user.ga_domain)
     self.assertEquals('*****@*****.**', user.email)
示例#8
0
 def testGetCurrent_ImpersonationInProd(self):
   # Verify that the crisismap_login cookie works for admins in prod.
   with test_utils.EnvContext(
       SERVER_SOFTWARE='Google App Engine/1.7.6',
       USER_ID='123456789', USER_EMAIL='*****@*****.**',
       USER_ORGANIZATION='alpha.test', USER_IS_ADMIN='1',
       HTTP_COOKIE='crisismap_login=t1000:sky.net:[email protected]'):
     user = users.GetCurrent()
     self.assertEquals('t1000', user.id)  # cookie should be used
     self.assertEquals('sky.net', user.ga_domain)
     self.assertEquals('*****@*****.**', user.email)
示例#9
0
 def testGetCurrent_ImpersonationInDev(self):
   # Verify that the crisismap_login cookie works in development.
   with test_utils.EnvContext(
       SERVER_SOFTWARE='Development/1.0',
       USER_ID='123456789', USER_EMAIL='*****@*****.**',
       USER_ORGANIZATION='alpha.test',
       HTTP_COOKIE='crisismap_login=t1000:sky.net:[email protected]'):
     user = users.GetCurrent()
     self.assertEquals('t1000', user.id)  # cookie should be used
     self.assertEquals('sky.net', user.ga_domain)
     self.assertEquals('*****@*****.**', user.email)
示例#10
0
 def testGetCurrent_AfterGetForEmailWithExistingGoogleAccount(self):
   self.mox.stubs.Set(users, '_EmailToGaeUserId', {
       '*****@*****.**': '123456789',
       '*****@*****.**': '123456789'
   }.get)
   # Introduce an e-mail address that's new to us but has a Google Account.
   # GetForEmail should associate the address with the Google Account.
   self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
   # A sign-in with that Google Account ID should get the same UserModel,
   # even if the e-mail address is different.
   with test_utils.EnvContext(USER_ID='123456789',
                              USER_EMAIL='*****@*****.**'):
     self.assertEquals('1', users.GetCurrent().id)
   # Any other e-mail address associated with the same Google Account should
   # yield the same UserModel.
   self.assertEquals('1', users.GetForEmail('*****@*****.**').id)