-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2182 from City-of-Helsinki/HL-891-csrf-token
HL-891: Fix CSRF token issues
- Loading branch information
Showing
17 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import factory | ||
import pytest | ||
from rest_framework.test import APIClient | ||
|
||
from applications.tests.factories import ApplicationFactory | ||
from common.tests.conftest import * # noqa | ||
from companies.tests.conftest import * # noqa | ||
from helsinkibenefit.tests.conftest import * # noqa | ||
|
||
|
||
@pytest.fixture | ||
def gdpr_api_client(): | ||
return APIClient() | ||
|
||
|
||
@pytest.fixture | ||
def application(mock_get_organisation_roles_and_create_company): | ||
# Application which belongs to logged in user company | ||
with factory.Faker.override_default_locale("fi_FI"): | ||
app = ApplicationFactory() | ||
app.company = mock_get_organisation_roles_and_create_company | ||
app.save() | ||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from rest_framework.reverse import reverse | ||
|
||
from common.tests.conftest import get_client_user | ||
|
||
|
||
def test_applications_unauthorized(api_client, application): | ||
response = api_client.get(reverse("users-me")) | ||
user = get_client_user(api_client) | ||
assert response.status_code == 200 | ||
assert response.data["id"] == str(user.id) | ||
assert len(response.data["csrf_token"]) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable scanjs-rules/identifier_localStorage */ | ||
|
||
const IS_CLIENT = typeof window !== 'undefined'; | ||
|
||
export const getLocalStorageItem = (key: string): string => | ||
IS_CLIENT ? localStorage.getItem(key) || '' : ''; | ||
|
||
export const setLocalStorageItem = (key: string, value: string): void => | ||
IS_CLIENT && localStorage.setItem(key, value); | ||
|
||
export const removeLocalStorageItem = (key: string): void => | ||
IS_CLIENT && localStorage.removeItem(key); | ||
|
||
/* eslint-enable scanjs-rules/identifier_localStorage */ |