Beispiel #1
0
 def default_response(self):
     totp_secret = self.request.session.get_totp_secret()
     return {
         "provision_totp_form": ProvisionTOTPForm(totp_secret=totp_secret),
         "provision_totp_uri": otp.generate_totp_provisioning_uri(
             totp_secret,
             self.request.user.username,
             issuer_name=self.request.registry.settings["site.name"],
         ),
     }
Beispiel #2
0
 def default_response(self):
     totp_secret = self.request.session.get_totp_secret()
     return {
         "provision_totp_secret": base64.b32encode(totp_secret).decode(),
         "provision_totp_form": ProvisionTOTPForm(totp_secret=totp_secret),
         "provision_totp_uri": otp.generate_totp_provisioning_uri(
             totp_secret,
             self.request.user.username,
             issuer_name=self.request.registry.settings["site.name"],
         ),
     }
Beispiel #3
0
def test_generate_totp_provisioning_uri():
    secret = b"F" * 32
    username = "******"
    issuer_name = "pypi.org"
    uri = generate_totp_provisioning_uri(secret, username, issuer_name=issuer_name)

    parsed = urlparse(uri)

    assert parsed.scheme == "otpauth"
    assert parsed.netloc == "totp"
    assert parsed.path == f"/{issuer_name}:{username}"

    query = parse_qsl(parsed.query)

    assert ("digits", "6") in query
    assert ("secret", b32encode(secret).decode()) in query
    assert ("algorithm", "SHA1") in query
    assert ("issuer", issuer_name) in query
    assert ("period", "30") in query
Beispiel #4
0
def test_generate_totp_provisioning_uri():
    secret = b"F" * 32
    username = "******"
    issuer_name = "pypi.org"
    uri = generate_totp_provisioning_uri(secret,
                                         username,
                                         issuer_name=issuer_name)

    parsed = urlparse(uri)

    assert parsed.scheme == "otpauth"
    assert parsed.netloc == "totp"
    assert parsed.path == f"/{issuer_name}:{username}"

    query = parse_qsl(parsed.query)

    assert ("digits", "6") in query
    assert ("secret", b32encode(secret).decode()) in query
    assert ("algorithm", "SHA1") in query
    assert ("issuer", issuer_name) in query
    assert ("period", "30") in query