def check_basic_auth(self, header, project): """Parse basic authorization header :param header: authorization header value """ header = extract_if_startswith(header, "Basic") if not header: return False public_key, private_key = b64decode(header.strip()).split(":") return self.check_key(private_key, public_key, project)
def check_gottwall_auth(self, header, project): """Check X-GottWall-Auth :param header: header string value :param project: project name """ header = extract_if_startswith(header, "GottWallS1") if not header: return False ts, sign, base = header.split() return self.check_sign(project, sign, ts, base)
def check_gottwall_auth(self, header, project): """Check X-GottWall-Auth :param header: header string value GoottWallS1 1391854203 09944becfa73f5a2b433468b20cf417c 1000 :param project: project name """ header = extract_if_startswith(header, "GottWallS1") if not header: return False ts, sign, base = header.split() return self.check_sign(project, sign, ts, base)
def check_gottwall_auth_s2(self, header): """Check client authentication :param header: authentication header string GoottWallS2 1391854203 09944becfa73f5a2b433468b20cf417c 1000 test_project """ header = extract_if_startswith(header, "GottWallS2") if not header: return False try: ts, sign, base, project = header.split() if self.check_sign(project, sign, ts, base): self.project = project return True except Exception as e: return True
def test_extract_if_startswith(): assert extract_if_startswith("Basic ejfknwejklfnwejfnl", "Basic ") == "ejfknwejklfnwejfnl"