Skip to content

Commit 82839fc

Browse files
committed
Remove authentication views
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 357b37b commit 82839fc

7 files changed

Lines changed: 5 additions & 154 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ Version v30.0.0
6262
- Add authentication for REST API endpoint.
6363
The autentication is disabled by default and can be enabled using the
6464
SCANCODEIO_REQUIRE_AUTHENTICATION settings.
65-
When enabled, users have to authenticate through a login form in the Web UI, or using
65+
When enabled, users have to authenticate using
6666
their API Key in the REST API.
67-
The API Key can be viewed in the Web UI "Profile settings" view once logged-in.
6867
Users can be created using the Django "createsuperuser" management command.
6968

7069
Other:

vulnerabilities/templates/accounts/profile.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

vulnerabilities/templates/base.html

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!DOCTYPE html class="has-navbar-fixed-top">
1+
<!DOCTYPE html>
2+
<html lang="en">
23
{% load static %}
34
<head>
45
<title>VulnerableCode</title>
@@ -23,27 +24,6 @@
2324
<a class="navbar-item" href="{% url 'vulnerability_search' %}">
2425
Vulnerabilities
2526
</a>
26-
{% if user.is_authenticated %}
27-
<div class="navbar-item has-dropdown is-hoverable">
28-
<a class="navbar-link">
29-
{{ user.username }}
30-
</a>
31-
<div class="navbar-dropdown is-right">
32-
<a class="navbar-item" href="{% url 'account_profile' %}">
33-
Profile settings
34-
</a>
35-
<a class="navbar-item" href="{% url 'logout' %}">
36-
Sign out
37-
</a>
38-
</div>
39-
{% endif %}
40-
</div>
41-
<div class="navbar-end">
42-
{% if not user.is_authenticated %}
43-
<a class="navbar-item is-right" href="{% url 'login' %}">
44-
Sign in
45-
</a>
46-
{% endif %}
4727
</div>
4828
</div>
4929
</nav>
@@ -70,4 +50,5 @@
7050
</footer>
7151
</body>
7252
{% block javascript %}
73-
{% endblock %}
53+
{% endblock %}
54+
</html>

vulnerabilities/templates/registration/login.html

Lines changed: 0 additions & 41 deletions
This file was deleted.

vulnerabilities/tests/test_auth.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313
from django.contrib.auth import get_user_model
1414
from django.contrib.auth.models import AnonymousUser
1515
from django.test import TestCase
16-
from django.urls import reverse
1716

1817
TEST_PASSWORD = "secret"
1918

2019
User = get_user_model()
2120

22-
login_url = reverse("login")
23-
logout_url = reverse("logout")
24-
profile_url = reverse("account_profile")
2521
api_package_url = "/api/packages/"
2622
login_redirect_url = settings.LOGIN_REDIRECT_URL
2723

@@ -31,45 +27,6 @@ def setUp(self):
3127
self.anonymous_user = AnonymousUser()
3228
self.basic_user = User.objects.create_user(username="basic_user", password=TEST_PASSWORD)
3329

34-
def test_vulnerablecode_auth_login_view(self):
35-
data = {"username": self.basic_user.username, "password": ""}
36-
response = self.client.post(login_url, data)
37-
form = response.context_data["form"]
38-
expected_error = {"password": ["This field is required."]}
39-
self.assertEqual(expected_error, form.errors)
40-
41-
data = {"username": self.basic_user.username, "password": "wrong"}
42-
response = self.client.post(login_url, data)
43-
form = response.context_data["form"]
44-
expected_error = {
45-
"__all__": [
46-
"Please enter a correct username and password. "
47-
"Note that both fields may be case-sensitive."
48-
]
49-
}
50-
self.assertEqual(expected_error, form.errors)
51-
52-
data = {"username": self.basic_user.username, "password": TEST_PASSWORD}
53-
response = self.client.post(login_url, data, follow=True)
54-
self.assertRedirects(response, login_redirect_url)
55-
expected = '<a class="navbar-link">basic_user</a>'
56-
self.assertContains(response, expected, html=True)
57-
58-
def test_vulnerablecode_auth_logout_view(self):
59-
response = self.client.get(logout_url)
60-
self.assertRedirects(response, login_url)
61-
62-
self.client.login(username=self.basic_user.username, password=TEST_PASSWORD)
63-
response = self.client.get(logout_url)
64-
self.assertRedirects(response, login_url)
65-
66-
def test_vulnerablecode_account_profile_view(self):
67-
self.client.login(username=self.basic_user.username, password=TEST_PASSWORD)
68-
response = self.client.get(profile_url)
69-
expected = '<label class="label">API Key</label>'
70-
self.assertContains(response, expected, html=True)
71-
self.assertContains(response, self.basic_user.auth_token.key)
72-
7330
def test_vulnerablecode_auth_api_required_authentication(self):
7431
response = self.client.get(api_package_url)
7532
expected = {"detail": "Authentication credentials were not provided."}

vulnerabilities/views.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from urllib.parse import urlencode
1111

12-
from django.contrib.auth.mixins import LoginRequiredMixin
1312
from django.core.paginator import PageNotAnInteger
1413
from django.core.paginator import Paginator
1514
from django.db.models import Count
@@ -18,7 +17,6 @@
1817
from django.shortcuts import render
1918
from django.urls import reverse
2019
from django.views import View
21-
from django.views import generic
2220
from django.views.generic.edit import UpdateView
2321
from django.views.generic.list import ListView
2422

@@ -169,7 +167,3 @@ def schema_view(request):
169167
if request.method != "GET":
170168
return HttpResponseNotAllowed()
171169
return render(request, "api_doc.html")
172-
173-
174-
class AccountProfileView(LoginRequiredMixin, generic.TemplateView):
175-
template_name = "accounts/profile.html"

vulnerablecode/urls.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#
99

1010
from django.contrib import admin
11-
from django.contrib.auth import views as auth_views
1211
from django.urls import include
1312
from django.urls import path
1413
from rest_framework.routers import DefaultRouter
@@ -17,7 +16,6 @@
1716
from vulnerabilities.api import CPEViewSet
1817
from vulnerabilities.api import PackageViewSet
1918
from vulnerabilities.api import VulnerabilityViewSet
20-
from vulnerabilities.views import AccountProfileView
2119
from vulnerabilities.views import HomePage
2220
from vulnerabilities.views import PackageSearchView
2321
from vulnerabilities.views import PackageUpdate
@@ -49,12 +47,5 @@ def __init__(self, *args, **kwargs):
4947
path("vulnerabilities/<int:pk>", VulnerabilityDetails.as_view(), name="vulnerability_view"),
5048
path("vulnerabilities/search", VulnerabilitySearchView.as_view(), name="vulnerability_search"),
5149
path("", HomePage.as_view(), name="home"),
52-
path("accounts/profile/", AccountProfileView.as_view(), name="account_profile"),
53-
path("accounts/login/", auth_views.LoginView.as_view(), name="login"),
54-
path(
55-
"accounts/logout/",
56-
auth_views.LogoutView.as_view(next_page="login"),
57-
name="logout",
58-
),
5950
path(r"api/", include(api_router.urls)),
6051
]

0 commit comments

Comments
 (0)