Ejemplo n.º 1
0
    def test_non_existing_group(self, mocker):
        """
        Given:
            - An app client object
            - A scim argument that contains an ID and displayName of a mon_existing group
        When:
            - The group not exists in the application
            - Calling the main function with 'iam-get-group' command
        Then:
            - Ensure the resulted 'CommandResults' object holds information about an unsuccessful result.
        """
        mock_result = mocker.patch('OracleIAM.CommandResults')

        args = {
            "scim": "{\"id\": \"1234\", \"displayName\": \"The group name\"}"
        }

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})
            m.get('https://test.com/admin/v1/Groups/1234',
                  status_code=404,
                  text='Group Not Found')

            client = mock_client()
            get_group_command(client, args)

        assert mock_result.call_args.kwargs['outputs']['success'] is False
        assert mock_result.call_args.kwargs['outputs']['id'] == '1234'
        assert mock_result.call_args.kwargs['outputs']['errorCode'] == 404
        assert mock_result.call_args.kwargs['outputs'][
            'errorMessage'] == 'Group Not Found'
Ejemplo n.º 2
0
    def test_with_display_name(self, mocker):
        """
        Given:
            - An app client object
            - A scim argument that contains a displayName of a group
        When:
            - The group exists in the application
            - Calling the main function with 'iam-get-group' command
        Then:
            - Ensure the resulted 'CommandResults' object holds the correct group details
        """
        mock_result = mocker.patch('OracleIAM.CommandResults')

        args = {"scim": "{\"displayName\": \"The group name\"}"}

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})
            m.get(
                'https://test.com/admin/v1/Groups?filter=displayName eq "The+group+name"',
                json={
                    'totalResults': 1,
                    'Resources': [APP_GROUP_OUTPUT]
                },
            )

            client = mock_client()
            get_group_command(client, args)

        assert mock_result.call_args.kwargs['outputs']['id'] == '1234'
        assert mock_result.call_args.kwargs['outputs'][
            'displayName'] == 'The group name'
Ejemplo n.º 3
0
    def test_id_and_display_name_empty(self):
        """
        Given:
            - An app client object
            - A scim argument that not contains an ID and displayName of a group
        When:
            - Calling the main function with 'iam-get-group' command
        Then:
            - Ensure that an error is raised with an expected message.
        """

        args = {"scim": {}}

        with requests_mock.Mocker() as m:
            m.post('https://test.com/oauth2/v1/token', json={})
            client = mock_client()

            with pytest.raises(Exception) as e:
                get_group_command(client, args)

        assert str(
            e.value
        ) == 'You must supply either "id" or "displayName" in the scim data'