Exemplo n.º 1
0
    def raise_error(self, exc, identity=None):
        if isinstance(exc, ApiUnauthorized):
            six.reraise(
                InvalidIdentity,
                InvalidIdentity(self.message_from_error(exc),
                                identity=identity),
                sys.exc_info()[2],
            )
        elif isinstance(exc, ApiError):
            if exc.json:
                error_fields = self.error_fields_from_json(exc.json)
                if error_fields is not None:
                    six.reraise(IntegrationFormError,
                                IntegrationFormError(error_fields),
                                sys.exc_info()[2])

            six.reraise(IntegrationError,
                        IntegrationError(self.message_from_error(exc)),
                        sys.exc_info()[2])
        elif isinstance(exc, IntegrationError):
            raise
        else:
            self.logger.exception(six.text_type(exc))
            six.reraise(IntegrationError,
                        IntegrationError(self.message_from_error(exc)),
                        sys.exc_info()[2])
Exemplo n.º 2
0
    def test_fetch_error_invalid_identity(self, mock_compare_commits, mock_handle_invalid_identity):
        self.login_as(user=self.user)
        org = self.create_organization(owner=self.user, name="baz")

        repo = Repository.objects.create(name="example", provider="dummy", organization_id=org.id)
        release = Release.objects.create(organization_id=org.id, version="abcabcabc")

        commit = Commit.objects.create(organization_id=org.id, repository_id=repo.id, key="a" * 40)

        ReleaseHeadCommit.objects.create(
            organization_id=org.id, repository_id=repo.id, release=release, commit=commit
        )

        refs = [{"repository": repo.name, "commit": "b" * 40}]

        release2 = Release.objects.create(organization_id=org.id, version="12345678")

        usa = UserSocialAuth.objects.create(user=self.user, provider="dummy")

        mock_compare_commits.side_effect = InvalidIdentity(identity=usa)

        fetch_commits(
            release_id=release2.id, user_id=self.user.id, refs=refs, previous_release_id=release.id
        )

        mock_handle_invalid_identity.assert_called_once_with(identity=usa, commit_failure=True)
Exemplo n.º 3
0
 def check_auth(self, *args, **kwargs):
     """
     Checks if auth is expired and if so refreshes it
     """
     time_expires = self.identity.data.get("expires")
     if time_expires is None:
         raise InvalidIdentity("OAuth2ApiClient requires identity with specified expired time")
     if int(time_expires) <= int(time()):
         self.identity.get_provider().refresh_identity(self.identity, *args, **kwargs)
    def test_fetch_error_invalid_identity(self, mock_compare_commits,
                                          mock_handle_invalid_identity):
        self.login_as(user=self.user)
        org = self.create_organization(owner=self.user, name='baz')

        repo = Repository.objects.create(
            name='example',
            provider='dummy',
            organization_id=org.id,
        )
        release = Release.objects.create(
            organization_id=org.id,
            version='abcabcabc',
        )

        commit = Commit.objects.create(
            organization_id=org.id,
            repository_id=repo.id,
            key='a' * 40,
        )

        ReleaseHeadCommit.objects.create(
            organization_id=org.id,
            repository_id=repo.id,
            release=release,
            commit=commit,
        )

        refs = [{
            'repository': repo.name,
            'commit': 'b' * 40,
        }]

        release2 = Release.objects.create(
            organization_id=org.id,
            version='12345678',
        )

        usa = UserSocialAuth.objects.create(
            user=self.user,
            provider='dummy',
        )

        mock_compare_commits.side_effect = InvalidIdentity(identity=usa)

        fetch_commits(
            release_id=release2.id,
            user_id=self.user.id,
            refs=refs,
            previous_release_id=release.id,
        )

        mock_handle_invalid_identity.assert_called_once_with(
            identity=usa,
            commit_failure=True,
        )
Exemplo n.º 5
0
 def raise_error(self, exc):
     if isinstance(exc, ApiUnauthorized):
         raise InvalidIdentity(self.message_from_error(exc))
     elif isinstance(exc, ApiError):
         raise PluginError(self.message_from_error(exc))
     elif isinstance(exc, PluginError):
         raise
     else:
         self.logger.exception(six.text_type(exc))
         raise PluginError(self.message_from_error(exc))
Exemplo n.º 6
0
 def raise_error(self, exc, identity=None):
     if isinstance(exc, ApiUnauthorized):
         raise InvalidIdentity(self.message_from_error(exc), identity=identity).with_traceback(
             sys.exc_info()[2]
         )
     elif isinstance(exc, ApiError):
         raise PluginError(self.message_from_error(exc)).with_traceback(sys.exc_info()[2])
     elif isinstance(exc, PluginError):
         raise
     else:
         self.logger.exception(str(exc))
         raise PluginError(self.message_from_error(exc)).with_traceback(sys.exc_info()[2])
Exemplo n.º 7
0
 def raise_error(self, exc, identity=None):
     if isinstance(exc, ApiUnauthorized):
         six.reraise(
             InvalidIdentity,
             InvalidIdentity(self.message_from_error(exc), identity=identity),
             sys.exc_info()[2],
         )
     elif isinstance(exc, ApiError):
         six.reraise(PluginError, PluginError(self.message_from_error(exc)), sys.exc_info()[2])
     elif isinstance(exc, PluginError):
         raise
     else:
         self.logger.exception(six.text_type(exc))
         six.reraise(PluginError, PluginError(self.message_from_error(exc)), sys.exc_info()[2])
Exemplo n.º 8
0
    def raise_error(self, exc: ApiError, identity: Optional[Identity] = None) -> None:
        if isinstance(exc, ApiUnauthorized):
            raise InvalidIdentity(self.message_from_error(exc), identity=identity).with_traceback(
                sys.exc_info()[2]
            )
        elif isinstance(exc, ApiError):
            if exc.json:
                error_fields = self.error_fields_from_json(exc.json)
                if error_fields is not None:
                    raise IntegrationFormError(error_fields).with_traceback(sys.exc_info()[2])

            raise IntegrationError(self.message_from_error(exc)).with_traceback(sys.exc_info()[2])
        elif isinstance(exc, IntegrationError):
            raise
        else:
            self.logger.exception(str(exc))
            raise IntegrationError(self.message_from_error(exc)).with_traceback(sys.exc_info()[2])