diff --git a/nsupdate/api/_tests/test_api.py b/nsupdate/api/_tests/test_api.py index 499af3c..ff69f1d 100644 --- a/nsupdate/api/_tests/test_api.py +++ b/nsupdate/api/_tests/test_api.py @@ -17,9 +17,10 @@ def test_myip(client): assert response.content in ['127.0.0.1', '::1'] -def test_nic_update(client): +def test_nic_update_noauth(client): response = client.get(reverse('nic_update')) assert response.status_code == 401 + assert response.content == "badauth" def make_basic_auth_header(username, password): @@ -27,6 +28,13 @@ def make_basic_auth_header(username, password): return "Basic " + base64.b64encode("%s:%s" % (username, password)) +def test_nic_update_badauth(client): + response = client.get(reverse('nic_update'), + HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, "wrong")) + assert response.status_code == 401 + assert response.content == "badauth" + + def test_nic_update_authorized(client): response = client.get(reverse('nic_update'), HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET)) diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index 730edde..4bcf3ee 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -184,7 +184,7 @@ class NicUpdateView(View): auth = request.META.get('HTTP_AUTHORIZATION') if auth is None: logger.warning('%s - received no auth' % (hostname, )) - return basic_challenge("authenticate to update DNS", 'noauth') + return basic_challenge("authenticate to update DNS", 'badauth') username, password = basic_authenticate(auth) if not check_api_auth(username, password): logger.warning('%s - received bad credentials, username: %s' % (hostname, username, ))