Example #1
0
def test_expand_and_process_access_groups(permission_set, expected):
    authobj = Authorization(
        "some_user",
        {"fake": "config"},
        {"fake": "config"},
        log
    )
    actual = authobj.expand_and_process_access_groups(permission_set)
    assert actual == expected
Example #2
0
def test_get_access_user_permissions_from_owner_conf(mocked_get_groups,
                                                     expected_operations,
                                                     access_user_dict,
                                                     owner_auth_conf):
    """Test the un-processed permissions of owner conf."""
    mocked_get_groups.return_value = (["group:blah"], [])
    authobj = Authorization("some_user", owner_auth_conf, {"fake": "config"},
                            log)
    permitted_operations = authobj.get_access_user_permissions_from_owner_conf(
        access_user_dict)
    assert permitted_operations == expected_operations
Example #3
0
def test_get_permitted_operations(
    mocked_get_groups,
    expected_operations,
    owner_name,
    owner_groups,
    user_name,
    user_groups,
):
    mocked_get_groups.side_effect = [(owner_groups, []), (user_groups, [])]
    auth_obj = Authorization(owner_name, FAKE_USER_CONF, FAKE_SITE_CONF, log)
    actual_operations = auth_obj.get_permitted_operations(
        access_user=user_name)
    assert actual_operations == expected_operations
Example #4
0
def test_is_permitted(
    mocked_get_groups,
    owner_name,
    user_name,
    get_permitted_operations_is_called,
    expected,
):
    mocked_get_groups.side_effect = [([""], []), ([""], [])]
    auth_obj = Authorization(owner_name, FAKE_USER_CONF, FAKE_SITE_CONF, log)
    auth_obj.get_permitted_operations = Mock(return_value=["fake_operation"])
    actual = auth_obj.is_permitted(access_user=user_name,
                                   operation="fake_operation")
    if get_permitted_operations_is_called:
        auth_obj.get_permitted_operations.assert_called_with(user_name)
    assert actual == expected
Example #5
0
def test_get_op_name(mut_field_name, operation, expected_op_name):
    mock_authobj = Authorization("some_user", {"fake": "config"},
                                 {"fake": "config"}, log)
    auth_middleware = AuthorizationMiddleware
    auth_middleware.auth = mock_authobj
    actual_op_name = auth_middleware.get_op_name(auth_middleware,
                                                 mut_field_name, operation)
    assert actual_op_name == expected_op_name
Example #6
0
 def set_auth(self):
     """Create authorization object.
     One for the lifetime of the UIServer.
     """
     return Authorization(getpass.getuser(),
                          self.config.CylcUIServer.user_authorization,
                          self.config.CylcUIServer.site_authorization,
                          self.log)