Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions xivo/http_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015-2024 The Wazo Authors (see the AUTHORS file)
# Copyright 2015-2026 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import annotations
Expand Down Expand Up @@ -49,9 +49,9 @@ def __init__(
'tenant_uuid': tenant_uuid,
}
super().__init__(
status_code=401,
message='Unauthorized',
error_id='unauthorized',
status_code=403,
message='Forbidden',
error_id='forbidden',
details=details,
)

Expand Down
36 changes: 35 additions & 1 deletion xivo/tests/test_auth_verifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015-2025 The Wazo Authors (see the AUTHORS file)
# Copyright 2015-2026 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest
Expand Down Expand Up @@ -66,6 +66,40 @@ def test_validate_token_with_no_acl_permission_raises_exception(self):
tenant_uuid,
)

def test_validate_token_with_no_acl_permission_raises_403(self):
mock_client = Mock()
mock_client.token.check.side_effect = MissingPermissionsTokenException
token_uuid = s.token
tenant_uuid = s.tenant
required_acl = s.acl

with pytest.raises(MissingPermissionsTokenAPIException) as exc_info:
self.helpers.validate_token(
mock_client,
token_uuid,
required_acl,
tenant_uuid,
)

assert exc_info.value.status_code == 403

def test_validate_invalid_token_raises_401(self):
mock_client = Mock()
mock_client.token.check.side_effect = InvalidTokenException
token_uuid = s.token
tenant_uuid = s.tenant
required_acl = s.acl

with pytest.raises(InvalidTokenAPIException) as exc_info:
self.helpers.validate_token(
mock_client,
token_uuid,
required_acl,
tenant_uuid,
)

assert exc_info.value.status_code == 401

def test_validate_token_raise_unreachable(self):
mock_client = Mock()
mock_client.token.check.side_effect = requests.RequestException
Expand Down