Пример #1
0
def add_fake_credentials(email, hasprinter=True):
    token = 'fakeoauth.py|noprinter'
    if hasprinter:
        token = 'fakeoauth.py'
    credentials = OAuth2Credentials(token, token, token,
                                    token, None, token, token)

    with app.app_context():
        oauthcredentials._save_credentials(email, credentials)
Пример #2
0
def add_fake_credentials(email, hasprinter=True):
    token = 'fakeoauth.py|noprinter'
    if hasprinter:
        token = 'fakeoauth.py'
    credentials = OAuth2Credentials(token, token, token, token, None, token,
                                    token)

    with app.app_context():
        oauthcredentials._save_credentials(email, credentials)
Пример #3
0
 def setUp(self):
     self._email = '*****@*****.**'
     self._credentials = oauth2client.client.OAuth2Credentials(
         access_token='token',
         client_id='bar',
         client_secret='bar',
         refresh_token='refresh',
         token_expiry=datetime.datetime.now() + datetime.timedelta(days=30),
         token_uri='http://example.com',
         user_agent='foo')
     with app.app_context():
         oauth._save_credentials(self._email, self._credentials)
Пример #4
0
 def setUp(self):
     self._email = '*****@*****.**'
     self._credentials = oauth2client.client.OAuth2Credentials(
                             access_token='token',
                             client_id='bar',
                             client_secret='bar',
                             refresh_token='refresh',
                             token_expiry=datetime.datetime.now() + datetime.timedelta(days=30),
                             token_uri='http://example.com',
                             user_agent='foo')
     with app.app_context():
         oauth._save_credentials(self._email, self._credentials)
Пример #5
0
    def test_oauth_flow(self):
        with app.app_context():
            app.config[
                'OAUTH_REDIRECT_URI'] = 'http://localhost:5000/oauthredirect'

            token = oauth.get_token(self._email)
            self.assertIsNone(token)
            url = oauth.get_authentication_prompt_url(self._email)
            self.assertIsNotNone(url)

            # open the oauth prompt url in a browser
            # start a web server and listen for the oauth callback
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind(('localhost', 5000))
            s.listen(1)
            s.settimeout(20)
            webbrowser.open(url)
            conn, addr = s.accept()
            conn.settimeout(20)
            try:
                response = conn.recv(4096)
            except socket.timeout:
                self.fail('Timeout while waiting for oauth callback')
            conn.send('HTTP/1.1 200 OK')
            conn.close()
            s.close()

            data = response.split()
            self.assertTrue(len(data) > 1)
            self.assertEqual(data[0], 'GET')
            url = data[1]
            url = 'http://example.com' + url
            access_code = oauth.get_code_from_url(url)

            token = oauth.authorize_user_by_code(access_code, self._email)
            token_from_db = oauth.get_token(self._email)
            self.assertEqual(token, token_from_db)

            credentials = oauth._get_credentials(self._email)
            self.assertIsNotNone(credentials)
            self._saved_credentials = oauth._get_credentials(self._email)

            credentials.token_expiry = datetime.datetime.now(
            ) - datetime.timedelta(minutes=15)
            oauth._save_credentials(self._email, credentials)

            # Check if the access token is getting refreshed correctly.
            token = oauth.get_token(self._email)
            self.assertIsNotNone(token)
            self._saved_credentials = oauth._get_credentials(self._email)
Пример #6
0
    def test_oauth_flow(self):
        with app.app_context():
            app.config['OAUTH_REDIRECT_URI'] = 'http://localhost:5000/oauthredirect'
            
            token = oauth.get_token(self._email)
            self.assertIsNone(token)
            url = oauth.get_authentication_prompt_url(self._email)
            self.assertIsNotNone(url)
        
            # open the oauth prompt url in a browser
            # start a web server and listen for the oauth callback
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind(('localhost', 5000))
            s.listen(1)
            s.settimeout(20)
            webbrowser.open(url)
            conn, addr = s.accept()
            conn.settimeout(20)
            try:
                response = conn.recv(4096)
            except socket.timeout:
                self.fail('Timeout while waiting for oauth callback')
            conn.send('HTTP/1.1 200 OK')
            conn.close()
            s.close()

            data = response.split()
            self.assertTrue(len(data) > 1)
            self.assertEqual(data[0], 'GET')
            url = data[1]
            url = 'http://example.com' + url
            access_code = oauth.get_code_from_url(url)

            token = oauth.authorize_user_by_code(access_code, self._email)
            token_from_db = oauth.get_token(self._email)
            self.assertEqual(token, token_from_db)
            
            credentials = oauth._get_credentials(self._email)
            self.assertIsNotNone(credentials)
            self._saved_credentials = oauth._get_credentials(self._email)

            credentials.token_expiry = datetime.datetime.now() - datetime.timedelta(minutes=15)
            oauth._save_credentials(self._email, credentials)
            
            # Check if the access token is getting refreshed correctly.
            token = oauth.get_token(self._email)
            self.assertIsNotNone(token)
            self._saved_credentials = oauth._get_credentials(self._email)
Пример #7
0
 def tearDown(self):
     with app.app_context():
         oauth._save_credentials(self._email, self._saved_credentials)
Пример #8
0
 def tearDown(self):
     with app.app_context():
         oauth._save_credentials(self._email, self._saved_credentials)