示例#1
0
def test_simpleloginform_valid_data(settings):
    settings.DJCL_MONERO_NETWORK = "mainnet"
    request = MagicMock()
    form = SimpleLoginForm(
        request=request,
        data={
            "address": VALID_ADDRESS,
            "challenge": "12345678",
            "signature": "some valid signature",
        },
    )
    with patch("django_cryptolock.forms.authenticate") as auth_mock:
        auth_mock.return_value = mommy.make(User)
        request.session.get.return_value = "12345678"
        assert form.is_valid()
示例#2
0
def test_simpleloginform_expired_challenge(settings):
    settings.DJCL_MONERO_NETWORK = "mainnet"
    mommy.make(Challenge, challenge="12345678", expires=timezone.now())
    request = MagicMock()
    request.build_absolute_uri.return_value = "http://something/"
    form = SimpleLoginForm(
        request=request,
        data={
            "address": VALID_MONERO_ADDRESS,
            "challenge": gen_challenge(request, "12345678"),
            "signature": "some valid signature",
        },
    )
    with patch("django_cryptolock.forms.authenticate") as auth_mock:
        auth_mock.return_value = mommy.make(User)
        assert not form.is_valid()
示例#3
0
def test_simpleloginform_generates_no_new_challenge():
    request = MagicMock()
    request.build_absolute_uri.return_value = "http://something/"
    assert not Challenge.objects.all().exists()

    form = SimpleLoginForm(request=request, data={"address": ""})
    assert not Challenge.objects.all().exists()
    assert not form.initial.get("challenge")
示例#4
0
def test_simpleloginform_generates_no_new_challenge():
    request = MagicMock()
    initial = {}
    request.session.__setitem__.side_effect = initial.__setitem__
    request.session.__getitem__.side_effect = initial.__getitem__
    form = SimpleLoginForm(request=request, data={"address": ""})
    assert not form.initial.get("challenge")
    assert not initial.get("current_challenge")
示例#5
0
def test_simpleloginform_generates_new_challenge():
    request = MagicMock()
    initial = {}
    request.session.__setitem__.side_effect = initial.__setitem__
    request.session.__getitem__.side_effect = initial.__getitem__
    form = SimpleLoginForm(request=request)
    assert form.initial.get("challenge")
    assert initial["current_challenge"] == form.initial.get("challenge")
示例#6
0
def test_simpleloginform_generates_new_challenge():
    request = MagicMock()
    request.build_absolute_uri.return_value = "http://something/"
    assert not Challenge.objects.all().exists()

    form = SimpleLoginForm(request=request)
    challenge = Challenge.objects.first()
    assert form.initial.get("challenge")
    assert form.initial.get("challenge") == gen_challenge(
        request, challenge.challenge)
    assert form.initial.get("challenge").startswith("bitid://something")