def test_secret_key_generation_custom_filename(self): filename = 'testfile.txt' secret_key = secret_key_generator.generate(file_name=filename) self.assertEqual(properties.DEFAULT_LENGTH_OF_SECRET_KEY, len(secret_key)) self.assertTrue(os.path.isfile(filename)) self.assertEqual(secret_key, self.get_secret_key_from_file(filename))
def test_secret_key_generation_custom_len(self): len_of_sk = 15 secret_key = secret_key_generator.generate(len_of_secret_key=len_of_sk) self.assertEqual(len_of_sk, len(secret_key)) self.assertTrue(os.path.isfile(properties.DEFAULT_FILE_NAME)) self.assertEqual( secret_key, self.get_secret_key_from_file(properties.DEFAULT_FILE_NAME))
def test_secret_key_generation_default(self): secret_key = secret_key_generator.generate() self.assertEqual(properties.DEFAULT_LENGTH_OF_SECRET_KEY, len(secret_key)) self.assertTrue(os.path.isfile(properties.DEFAULT_FILE_NAME)) self.assertEqual( secret_key, self.get_secret_key_from_file(properties.DEFAULT_FILE_NAME))
def test_secret_key_generation_custom_chars(self): chars = 'asd' secret_key = secret_key_generator.generate(chars=chars) self.assertEqual(properties.DEFAULT_LENGTH_OF_SECRET_KEY, len(secret_key)) self.assertTrue(os.path.isfile(properties.DEFAULT_FILE_NAME)) self.assertEqual( secret_key, self.get_secret_key_from_file(properties.DEFAULT_FILE_NAME)) self.assertTrue(self.validate_secret_key_with_string( secret_key, chars))
""" import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. from django.utils.crypto import get_random_string from secret_key_generator import secret_key_generator BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = secret_key_generator.generate() LIBRARIAN_KEY = secret_key_generator.generate( chars='abcdefghijklmnopqrstuvwxyz0123456789', len_of_secret_key=10, file_name='.librarian_key.txt') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv('DEBUG', False) == 'True' ALLOWED_HOSTS = ['*'] SITE_ID = 2 # Application definition
from secret_key_generator import secret_key_generator SECRET_KEY = secret_key_generator.generate()
https://docs.djangoproject.com/en/2.0/ref/settings/ """ from secret_key_generator import secret_key_generator import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECRET_KEY = 'n!89gn)d)(&&e6#*3^d7%#qs_ulqu2s3mr6vup&j55-@)++$)l' SECRET_KEY = secret_key_generator.generate( chars="abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)", file_name="e_commerce/secret.txt", len_of_secret_key=50) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',