def test_validate_address_unique(settings): settings.DJCL_MONERO_NETWORK = "mainnet" mommy.make(Address, address=VALID_ADDRESS) request = MagicMock() form = SimpleSignUpForm( request=request, data={ "username": "******", "address": VALID_ADDRESS, "challenge": "12345678", "signature": "some valid signature", }, ) assert not form.is_valid() assert "This address already exists" in form.errors["address"]
def test_simplesignupform_invalid_addr(): mommy.make(Challenge, challenge="12345678", expires=FUTURE_TIME) request = MagicMock() request.build_absolute_uri.return_value = "http://something/" form = SimpleSignUpForm( request=request, data={ "username": "******", "address": "bad addr", "challenge": gen_challenge(request, "12345678"), "signature": "some valid signature", }, ) assert not form.is_valid() assert "Invalid address" in form.errors["address"]
def test_simplesignupform_expired_challenge(settings): set_bitcoin_settings(settings) mommy.make(Challenge, challenge="12345678", expires=timezone.now()) request = MagicMock() request.build_absolute_uri.return_value = "http://something/" form = SimpleSignUpForm( request=request, data={ "username": "******", "address": VALID_BITCOIN_ADDRESS, "challenge": gen_challenge(request, "12345678"), "signature": "some valid signature", }, ) assert not form.is_valid()
def test_simplesignupform_valid_monero_addr(settings): set_monero_settings(settings) mommy.make(Challenge, challenge="12345678", expires=FUTURE_TIME) settings.DJCL_MONERO_NETWORK = "mainnet" request = MagicMock() request.build_absolute_uri.return_value = "http://something/" form = SimpleSignUpForm( request=request, data={ "username": "******", "address": VALID_MONERO_ADDRESS, "challenge": gen_challenge(request, "12345678"), "signature": "some valid signature", }, ) assert form.is_valid()
def test_validate_address_unique(settings): settings.DJCL_MONERO_NETWORK = "mainnet" mommy.make(Address, address=VALID_MONERO_ADDRESS) mommy.make(Challenge, challenge="12345678", expires=FUTURE_TIME) request = MagicMock() request.build_absolute_uri.return_value = "http://something/" form = SimpleSignUpForm( request=request, data={ "username": "******", "address": VALID_MONERO_ADDRESS, "challenge": gen_challenge(request, "12345678"), "signature": "some valid signature", }, ) assert not form.is_valid() assert "This address already exists" in form.errors["address"]
def test_simplesignupform_generates_no_new_challenge(): request = MagicMock() request.build_absolute_uri.return_value = "http://something/" assert not Challenge.objects.all().exists() form = SimpleSignUpForm(request=request, data={"address": ""}) assert not Challenge.objects.all().exists() assert not form.initial.get("challenge")
def test_simplesignupform_generaes_no_new_challenge(): request = MagicMock() initial = {} request.session.__setitem__.side_effect = initial.__setitem__ request.session.__getitem__.side_effect = initial.__getitem__ form = SimpleSignUpForm(request=request, data={"address": ""}) assert not form.initial.get("challenge") assert not initial.get("current_challenge")
def test_simplesignupform_generates_new_challenge(): request = MagicMock() request.build_absolute_uri.return_value = "http://something/" assert not Challenge.objects.all().exists() form = SimpleSignUpForm(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")