• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tableau / TabPy / 4694295226

pending completion
4694295226

Pull #595

github

GitHub
Merge a85607d7c into fad6807d4
Pull Request #595: TabPy Arrow Support

207 of 207 new or added lines in 7 files covered. (100.0%)

1317 of 2311 relevant lines covered (56.99%)

0.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.43
/tabpy/tabpy_server/handlers/basic_auth_server_middleware_factory.py
1
import base64
1✔
2
import secrets
1✔
3

4
from pyarrow.flight import ServerMiddlewareFactory, ServerMiddleware
1✔
5
from pyarrow.flight import FlightUnauthenticatedError
1✔
6

7
from tabpy.tabpy_server.handlers.util import hash_password
1✔
8

9
class BasicAuthServerMiddleware(ServerMiddleware):
1✔
10
    def __init__(self, token):
1✔
11
        self.token = token
×
12

13
    def sending_headers(self):
1✔
14
        return {"authorization": f"Bearer {self.token}"}
×
15

16
class BasicAuthServerMiddlewareFactory(ServerMiddlewareFactory):
1✔
17
    def __init__(self, creds):
1✔
18
        self.creds = creds
×
19
        self.tokens = {}
×
20

21
    def is_valid_user(self, username, password):
1✔
22
        if username not in self.creds:
×
23
            return False
×
24
        hashed_pwd = hash_password(username, password)
×
25
        return self.creds[username].lower() == hashed_pwd.lower()
×
26

27
    def start_call(self, info, headers):
1✔
28
        auth_header = None
×
29
        for header in headers:
×
30
            if header.lower() == "authorization":
×
31
                auth_header = headers[header][0]
×
32
                break
×
33

34
        if not auth_header:
×
35
            raise FlightUnauthenticatedError("No credentials supplied")
×
36
        
37
        auth_type, _, value = auth_header.partition(" ")
×
38

39
        if auth_type == "Basic":
×
40
            decoded = base64.b64decode(value).decode("utf-8")
×
41
            username, _, password = decoded.partition(":")
×
42
            if not self.is_valid_user(username, password):
×
43
                raise FlightUnauthenticatedError("Invalid credentials")
×
44
            token = secrets.token_urlsafe(32)
×
45
            self.tokens[token] = username
×
46
            return BasicAuthServerMiddleware(token)
×
47
        
48
        raise FlightUnauthenticatedError("No credentials supplied")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc