Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #20 from ethyca/assemble-root-access-token
Browse files Browse the repository at this point in the history
Set default value for encoding in validator
  • Loading branch information
pattisdr authored Jun 10, 2022
2 parents 12425de + 23e6573 commit 8037b85
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
7 changes: 0 additions & 7 deletions fides.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# [database]
# SERVER="db"
# USER="postgres"
# PASSWORD="216f4b49bea5da4f84f05288258471852c3e325cd336821097e1e65ff92b528a"
# DB="app"
# TEST_DB="test"

[database]
SERVER="localhost"
USER="postgres"
Expand Down
2 changes: 1 addition & 1 deletion fideslib/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def assemble_root_access_token(cls, values: Dict[str, str]) -> Dict[str, str]:
"OAUTH_ROOT_CLIENT_SECRET is required", SecuritySettings
)

encoding = values["ENCODING"]
encoding = values.get("ENCODING", "UTF-8")

salt = bcrypt.gensalt()
hashed_client_id = hashlib.sha512(value.encode(encoding) + salt).hexdigest()
Expand Down
13 changes: 13 additions & 0 deletions tests/assets/fides.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[database]
SERVER="testserver"
USER="postgres"
PASSWORD="postgres"
DB="test"
TEST_DB="test"

[security]
APP_ENCRYPTION_KEY = "atestencryptionkeythatisvalidlen"
CORS_ORIGINS = [ "http://test.com", "https://test.com",]
OAUTH_ROOT_CLIENT_ID = "testrootclientid"
OAUTH_ROOT_CLIENT_SECRET = "testrootclientsecret"
DRP_JWT_SECRET = "testdrpsecret"
20 changes: 20 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# pylint: disable=missing-function-docstring, redefined-outer-name

import os
from pathlib import Path
from unittest.mock import patch

import pytest

from fideslib.core.config import (
Expand All @@ -10,12 +14,28 @@
)
from fideslib.exceptions import MissingConfig

ROOT_PATH = Path().absolute()


@pytest.fixture
def config_dict(fides_toml_path):
yield load_toml([fides_toml_path])


@patch.dict(
os.environ,
{
"FIDES__CONFIG_PATH": str(ROOT_PATH / "tests" / "assets"),
},
clear=True,
)
def test_config_from_path() -> None:
"""Test reading config using the FIDESOPS__CONFIG_PATH option."""
config = get_config()
assert config.database.SERVER == "testserver"
assert config.security.APP_ENCRYPTION_KEY == "atestencryptionkeythatisvalidlen"


def test_database_settings_sqlalchemy_database_uri_str(config_dict):
expected = "postgresql://someuri:216f4b49bea5da4f84f05288258471852c3e325cd336821097e1e65ff92b528a@db:5432/test"
config_dict["database"]["SQLALCHEMY_DATABASE_URI"] = expected
Expand Down

0 comments on commit 8037b85

Please sign in to comment.