Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/auth/exceptions.py: 95.83%

24 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-06-11 15:37 +0000

1# Copyright (C) 2023 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15from buildgrid._exceptions import ServerError 

16 

17 

18class AuthError(ServerError): 

19 pass 

20 

21 

22class MissingTokenError(AuthError): 

23 def __init__(self) -> None: 

24 super().__init__("Missing authentication header field") 

25 

26 

27class InvalidAuthorizationHeaderError(AuthError): 

28 def __init__(self) -> None: 

29 super().__init__("Invalid authentication header field") 

30 

31 

32class InvalidTokenError(AuthError): 

33 def __init__(self) -> None: 

34 super().__init__("Invalid authentication token") 

35 

36 

37class ExpiredTokenError(AuthError): 

38 def __init__(self) -> None: 

39 super().__init__("Expired authentication token") 

40 

41 

42class UnboundedTokenError(AuthError): 

43 def __init__(self, context: str = "") -> None: 

44 message = "Unbounded authentication token" 

45 if context: 

46 message = f"{message}: {context}" 

47 super().__init__(message) 

48 

49 

50class UnexpectedTokenParsingError(AuthError): 

51 def __init__(self) -> None: 

52 super().__init__("Unexpected error parsing authentication token")