Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove aggregated computation #651

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
347d56b
chore: don't use django to serve files
vjousse Jul 1, 2024
cb03774
Add tooling to encrypt and decrypt files.
n1k0 May 6, 2024
43820ee
feat: encrypt files server side
vjousse Jul 1, 2024
b95cc9b
fix: modify nginx conf
vjousse Jul 1, 2024
acf8dbc
fix: we don't need to encrypt files directly
vjousse Jul 1, 2024
162890f
fix: we don't need status
vjousse Jul 1, 2024
affaab4
chore: remove fast-memoize
vjousse Jul 1, 2024
558dc88
fix: read processes only once
vjousse Jul 1, 2024
0f4278a
fix: compute everything at server start
vjousse Jul 1, 2024
b43855d
fix: add 32 chars encryption key
vjousse Jul 1, 2024
aa1515a
fix: processes values should be strings
vjousse Jul 2, 2024
ac4733f
fix: food impacts path
vjousse Jul 2, 2024
7ab7e61
chore: Django app `processes` is not needed anymore
vjousse Jul 2, 2024
cac6ae0
feat: add RSA crypt/encrypt POC
vjousse Jul 3, 2024
22d2757
chore: use decorators to test method verbs
vjousse Jul 4, 2024
a269bf6
test: simplify test output
vjousse Jul 4, 2024
a9c210c
fix: refactor and pass token when retrieving processes.
n1k0 Jul 4, 2024
b11b449
Decode processes from JSON value.
n1k0 Jul 4, 2024
b14451d
fix: check token and serve appropriate files
vjousse Jul 4, 2024
0d465e2
fix: always provide full impacts in test mode
vjousse Jul 4, 2024
2ab424d
Revert "Decode processes from JSON value."
n1k0 Jul 4, 2024
cd867fc
fix: remove unused variable
vjousse Jul 4, 2024
3e63c29
fix: pass strings to Elm
vjousse Jul 4, 2024
58b7b19
fix: retrieve detailed processes after login.
n1k0 Jul 8, 2024
7357992
chore: extract auth request code to Request.Auth.
n1k0 Jul 8, 2024
696fd29
chore: Move AllProcessesJson to Static.Db.
n1k0 Jul 8, 2024
121f560
chore: move user stuff to User.module.
n1k0 Jul 8, 2024
9149a5a
chore: Move static Json related stuff to Static.Json.
n1k0 Jul 8, 2024
3dad6c6
chore: remove encryption code
vjousse Jul 9, 2024
b75a554
chore: compute undetailed processes at server load
vjousse Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ [email protected],[email protected]
[email protected]
DJANGO_DEBUG=True
DJANGO_SECRET_KEY=please-change-this
DJANGO_BYPASS_AUTH=False
EMAIL_HOST_PASSWORD=please-change-this
EMAIL_HOST_USER=please-change-this
ENABLE_FOOD_SECTION=True
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,4 @@ jobs:
run: npm run test:client

- name: Run server tests
env:
DJANGO_BYPASS_AUTH: True
run: pipenv run backend/update.sh && npm run test:server-ci && npm run test:backend
1 change: 0 additions & 1 deletion .github/workflows/score_history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ jobs:
GITHUB_REF_NAME: ${{ github.ref_name }}
LAST_COMMIT_HASH: ${{ github.sha }}
SCALINGO_POSTGRESQL_SCORE_URL: ${{ secrets.SCALINGO_POSTGRESQL_TUNNEL_SCORE_URL }}
DJANGO_BYPASS_AUTH: True
NODE_ENV: "test"
SCALINGO_REGION: ${{ secrets.SCALINGO_REGION }}
SCALINGO_APP: ecobalyse
Expand Down
2 changes: 1 addition & 1 deletion .proxyrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"target": "http://127.0.0.1:8002/"
},
"/processes/": {
"target": "http://127.0.0.1:8002/"
"target": "http://127.0.0.1:8001/"
},
"/admin/": {
"target": "http://127.0.0.1:8002/"
Expand Down
37 changes: 19 additions & 18 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 73 additions & 53 deletions backend/authentication/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import json

from django.contrib.auth import get_user_model
from django.core import mail
from django.test import TestCase
from django.urls import reverse

from .models import EcobalyseUser


class DjangoAuthenticationTests(TestCase):
def test_unauthenticated_user_should_not_access_profile(self):
response = self.client.get(
reverse("profile"),
content_type="application/json",
)

assert response.status_code == 401

def test_authenticated_user_should_access_profile(self):
test_user = EcobalyseUser.objects.get_or_create(email="[email protected]")[0]
self.client.force_login(test_user)
response = self.client.get(
reverse("profile"),
content_type="application/json",
)
assert response.status_code == 200

assert response.json() == {
"email": "[email protected]",
"first_name": "",
"last_name": "",
"organization": "",
"terms_of_use": False,
"token": str(test_user.token),
}

def test_register_post(self):
# invalid mail
response = self.client.post(
Expand All @@ -21,7 +47,7 @@ def test_register_post(self):
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
assert response.status_code == 200
self.assertContains(response, "Saisissez une adresse de courriel valide")

# missing first name
Expand All @@ -37,7 +63,7 @@ def test_register_post(self):
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
assert response.status_code == 200
self.assertContains(response, "Ce champ est obligatoire")

# missing last name
Expand All @@ -53,7 +79,7 @@ def test_register_post(self):
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
assert response.status_code == 200
self.assertContains(response, "Ce champ est obligatoire")

# don't accept terms of use
Expand All @@ -69,7 +95,7 @@ def test_register_post(self):
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
assert response.status_code == 200
self.assertContains(response, "Ce champ est obligatoire")

# missing organization is OK
Expand All @@ -85,27 +111,27 @@ def test_register_post(self):
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content).get("success"), True)
assert response.status_code == 200
assert response.json().get("success")

with self.assertLogs(logger="mailauth.backends", level="ERROR") as cm:
# wrong json login url
response = self.client.get("/accounts/login/invalid-token?next=/")
self.assertEqual(response.status_code, 302)
assert response.status_code == 302

self.assertIn("BadSignature", " ".join(cm.output))
assert "BadSignature" in " ".join(cm.output)

# right json login url (it's transmitted through reading the outbox)
self.assertEqual(len(mail.outbox), 1)
assert len(mail.outbox) == 1
login_url = "/" + "/".join(
[x for x in mail.outbox[0].body.split("\n") if "http" in x][0].split("/")[
3:
]
)
response = self.client.get(login_url)
# a successful login should redirect to the "next" url
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/")
assert response.status_code == 302
assert response.url == "/"

# try to login again
response = self.client.post(
Expand All @@ -116,75 +142,69 @@ def test_register_post(self):
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content).get("success"), True)
assert response.status_code == 200
assert response.json().get("success")

login_url = "/" + "/".join(
[x for x in mail.outbox[0].body.split("\n") if "http" in x][0].split("/")[
3:
]
)
response = self.client.get(login_url)
# a successful login should redirect to the "next" url
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/")
assert response.status_code == 302
assert response.url == "/"

# get json profile
response = self.client.get(reverse("profile"))
jsonresp = json.loads(response.content)
self.assertEqual(
list(jsonresp.keys()),
[
"email",
"first_name",
"last_name",
"organization",
"terms_of_use",
"token",
],
)
self.assertEqual(
list(jsonresp.values())[:5], ["[email protected]", "John", "Doe", "", True]
)
created_user = EcobalyseUser.objects.get(email="[email protected]")

assert response.json() == {
"email": "[email protected]",
"first_name": "John",
"last_name": "Doe",
"organization": "",
"terms_of_use": True,
"token": str(created_user.token),
}

def test_as_admin(self):
# create an admin
get_user_model().objects.create_superuser(
super_user = get_user_model().objects.create_superuser(
"[email protected]", terms_of_use=True
)

# login as admin
response = self.client.post(
reverse("login"),
{
"email": "[email protected]",
"email": super_user.email,
"next": "/",
},
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content).get("success"), True)
assert response.status_code == 200
assert response.json().get("success")

login_url = "/" + "/".join(
[x for x in mail.outbox[0].body.split("\n") if "http" in x][0].split("/")[
3:
]
)
response = self.client.get(login_url)
# a successful login should redirect to the "next" url
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/")
assert response.status_code == 302
assert response.url == "/"

# get json profile
response = self.client.get(reverse("profile"))
jsonresp = json.loads(response.content)
self.assertEqual(
list(jsonresp.keys()),
[
"email",
"first_name",
"last_name",
"organization",
"terms_of_use",
"token",
],
)
self.assertEqual(
list(jsonresp.values())[:5], ["[email protected]", "", "", "", True]
)
response = self.client.get(reverse("profile"))

assert response.json() == {
"email": super_user.email,
"first_name": "",
"last_name": "",
"organization": "",
"terms_of_use": True,
"token": str(super_user.token),
}
Loading