示例#1
0
    def testConnectEmail(self):
        source = 'TheSource'
        token = 'TheToken'
        creds = gdata_lib.Creds()
        creds.user = '******'
        creds.password = '******'
        creds.tracker_auth_token = None
        self.mox.StubOutClassWithMocks(gd_ph_client, 'ProjectHostingClient')
        mocked_tcomm = self.mox.CreateMock(gdata_lib.TrackerComm)

        def set_token(*_args, **_kwargs):
            mocked_itclient.auth_token = cros_test_lib.EasyAttr(
                token_string=token)

        # Replay script
        mocked_itclient = gd_ph_client.ProjectHostingClient()
        mocked_itclient.ClientLogin(
            creds.user,
            creds.password,
            source=source,
            service='code',
            account_type='GOOGLE').WithSideEffects(set_token)
        self.mox.ReplayAll()

        # Verify
        with self.OutputCapturer():
            gdata_lib.TrackerComm.Connect(mocked_tcomm,
                                          creds,
                                          'TheProject',
                                          source=source)
        self.mox.VerifyAll()
        self.assertEquals(mocked_tcomm.it_client, mocked_itclient)
示例#2
0
    def testConnectToken(self):
        source = 'TheSource'
        token = 'TheToken'
        creds = gdata_lib.Creds()
        creds.user = '******'
        creds.password = '******'
        creds.tracker_auth_token = token
        mocked_tcomm = self.mox.CreateMock(gdata_lib.TrackerComm)

        self.mox.StubOutClassWithMocks(gd_ph_client, 'ProjectHostingClient')
        self.mox.StubOutClassWithMocks(gdata.gauth, 'ClientLoginToken')

        # Replay script
        mocked_itclient = gd_ph_client.ProjectHostingClient()
        mocked_token = gdata.gauth.ClientLoginToken(token)
        self.mox.ReplayAll()

        # Verify
        with self.OutputCapturer():
            gdata_lib.TrackerComm.Connect(mocked_tcomm,
                                          creds,
                                          'TheProject',
                                          source=source)
        self.mox.VerifyAll()
        self.assertEquals(mocked_tcomm.it_client, mocked_itclient)
        self.assertEquals(mocked_itclient.auth_token, mocked_token)
示例#3
0
    def testStoreLoadToken(self):
        # This is the replay script for the test.
        creds = gdata_lib.Creds()
        creds.user = self.USER

        # This is the test verification.
        with self.OutputCapturer():
            creds.SetDocsAuthToken(self.DOCS_TOKEN)
            self.assertEquals(self.DOCS_TOKEN, creds.docs_auth_token)
            self.assertTrue(creds.token_dirty)
            creds.SetTrackerAuthToken(self.TRACKER_TOKEN)
            self.assertEquals(self.TRACKER_TOKEN, creds.tracker_auth_token)
            self.assertTrue(creds.token_dirty)

            creds.StoreAuthToken(self.tempfile)
            self.assertEquals(self.DOCS_TOKEN, creds.docs_auth_token)
            self.assertEquals(self.TRACKER_TOKEN, creds.tracker_auth_token)
            self.assertFalse(creds.token_dirty)

            # Clear auth_tokens before loading from just-created file.
            creds.docs_auth_token = None
            creds.tracker_auth_token = None
            creds.user = None

            creds.LoadAuthToken(self.tempfile)
            self.assertEquals(self.DOCS_TOKEN, creds.docs_auth_token)
            self.assertEquals(self.TRACKER_TOKEN, creds.tracker_auth_token)
            self.assertFalse(creds.token_dirty)
            self.assertEquals(self.USER, creds.user)
示例#4
0
    def testStoreLoadCreds(self):
        # This is the replay script for the test.
        creds = gdata_lib.Creds()

        # This is the test verification.
        with self.OutputCapturer():
            creds.SetCreds(self.USER, self.PASSWORD)
            self.assertEquals(self.USER, creds.user)
            self.assertEquals(self.PASSWORD, creds.password)
            self.assertTrue(creds.creds_dirty)

            creds.StoreCreds(self.tempfile)
            self.assertEquals(self.USER, creds.user)
            self.assertEquals(self.PASSWORD, creds.password)
            self.assertFalse(creds.creds_dirty)

            # Clear user/password before loading from just-created file.
            creds.user = None
            creds.password = None
            self.assertEquals(None, creds.user)
            self.assertEquals(None, creds.password)

            creds.LoadCreds(self.tempfile)
            self.assertEquals(self.USER, creds.user)
            self.assertEquals(self.PASSWORD, creds.password)
            self.assertFalse(creds.creds_dirty)
示例#5
0
    def testSetTrackerToken(self):
        # This is the replay script for the test.
        creds = gdata_lib.Creds()

        # This is the test verification.
        creds.SetTrackerAuthToken(self.TRACKER_TOKEN)
        self.assertEquals(self.TRACKER_TOKEN, creds.tracker_auth_token)
        self.assertTrue(creds.token_dirty)
示例#6
0
    def testSetDocsToken(self):
        # This is the replay script for the test.
        creds = gdata_lib.Creds()

        # This is the test verification.
        creds.SetDocsAuthToken(self.DOCS_TOKEN)
        self.assertEquals(self.DOCS_TOKEN, creds.docs_auth_token)
        self.assertTrue(creds.token_dirty)
示例#7
0
    def testSetCreds(self):
        # This is the replay script for the test.
        creds = gdata_lib.Creds()

        # This is the test verification.
        creds.SetCreds(self.USER, password=self.PASSWORD)
        self.assertEquals(self.USER, creds.user)
        self.assertEquals(self.PASSWORD, creds.password)
        self.assertTrue(creds.creds_dirty)
示例#8
0
    def GenerateCreds(self, skip_user=False, skip_token=False):
        creds = gdata_lib.Creds()
        if not skip_user:
            creds.user = self.USER
            creds.password = self.PASSWORD

        if not skip_token:
            creds.docs_auth_token = self.TOKEN

        return creds
示例#9
0
    def testSetCredsNoPassword(self):
        # Add test-specific mocks/stubs
        self.PatchObject(getpass, 'getpass', return_value=self.PASSWORD)

        # This is the replay script for the test.
        creds = gdata_lib.Creds()

        # This is the test verification.
        creds.SetCreds(self.USER)
        self.assertEquals(self.USER, creds.user)
        self.assertEquals(self.PASSWORD, creds.password)
        self.assertTrue(creds.creds_dirty)
    def Run(self):
        """Validate existing auth token or generate new one from credentials."""
        import chromite.lib.gdata_lib as gdata_lib
        import gdata.spreadsheet.service

        self.creds = gdata_lib.Creds()
        self.gd_client = gdata.spreadsheet.service.SpreadsheetsService()
        self.it_client = gdata.projecthosting.client.ProjectHostingClient()

        self._LoadTokenFile()

        if not self._ValidateTrackerToken():
            if not self._GenerateTrackerToken():
                oper.Die('Failed to validate or generate Tracker token.')

        if not self._ValidateDocsToken():
            if not self._GenerateDocsToken():
                oper.Die('Failed to validate or generate Docs token.')

        self._SaveTokenFile()
示例#11
0
def PrepareCreds(cred_file, token_file, email, password):
  """Return a Creds object from given credentials.

  If |email| is given, the Creds object will contain that |email|
  and either the given |password| or one entered at a prompt.

  Otherwise, if |token_file| is given then the Creds object will have
  the auth_token from that file.

  Otherwise, if |cred_file| is given then the Creds object will have
  the email/password from that file.
  """

  creds = gdata_lib.Creds()

  if email:
    creds.SetCreds(email, password)
  elif token_file and os.path.exists(token_file):
    creds.LoadAuthToken(token_file)
  elif cred_file and os.path.exists(cred_file):
    creds.LoadCreds(cred_file)

  return creds