# Path: wsse/settings.py
# TIMESTAMP_DURATION = 2 * 60 * 60
# DRIFT_OFFSET = 2 * 60
# TIMESTAMP_FORMATS = [
# 	'%Y-%m-%dT%H:%M:%SZ',    # ISO 8601 in UTC (Z specifies 0 offset)
# 	'%Y-%m-%dT%H:%M:%S',     # ISO 8601 without timezone - assumed to be UTC
# 	'%Y-%m-%dT%H:%M:%S.%fZ', # ISO 8601 with microseconds in UTC
# 	'%Y-%m-%dT%H:%M:%S.%f',  # ISO 8601 with microseconds (assumed UTC)
# 	'%Y-%m-%dT%H:%M:%S%z',   # ISO 8601 with UTC offset
# 	'%Y-%m-%dT%H:%M:%S.%f%z' # ISO 8601 with microseconds and UTC offset
# 	]
# NONCE_LENGTH = 64
# NONCE_STORE = 'wsse.server.default.store.SQLiteNonceStore'
# NONCE_STORE_ARGS = (':memory:',)
# REQUEST_HEADER = 'X-WSSE'
# SECURITY_CHECK_NONCE = True
# SECURITY_CHECK_TIMESTAMP = True
# ALLOWED_DIGEST_ALGORITHMS = ['SHA256']
# PROHIBITED_DIGEST_ALGORITHMS = ['SHA1', 'MD5']
# SECRET_KEY_LENGTH = 64
# LOGGER_NAME = 'wsse'
# 
# Path: wsse/compat.py

# 
# Path: wsse/server/django/wsse/models.py
# class UserSecret(models.Model):
# 	'''
# 	The `UserSecret` object connects every user to their secret key. The secret
# 	key can be deleted to prevent access without affecting the user.
# 	'''
# 	user = models.OneToOneField(User, on_delete = models.CASCADE,
# 		db_index = True)
# 	secret = models.CharField(max_length = settings.SECRET_KEY_LENGTH,
# 		default = _generate_secret, blank = True, null = False)
# 
# Path: wsse/client/requests/auth.py
# class WSSEAuth(requests.auth.AuthBase):
# 	'''
# 	Attaches HTTP Digest Authentication to the given Request object.
# 
# 	Usage:
# 		requests.get(url, auth=WSSEAuth(username, password))
# 
# 	The auth object isreusable, and can be defined separately if several
# 	requests will be made with the same username & password pair.
# 
# 	:param username: username to include in request
# 	:type username: str
# 
# 	:param password: password to authenticate with
# 	:type password: str
# 	'''
# 	def __init__(self, username, password):
# 		self.token_builder = utils.TokenBuilder(username, password)
# 
# 	def __call__(self, r):
# 		'''Attach the appropriate request header to attempt WSSE authentication.'''
# 		token = self.token_builder.make_token()
# 		r.headers[settings.REQUEST_HEADER] = token
# 		return r


from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.contrib.auth.models import User
from rest_framework import status
from wsse import settings
from wsse.compat import reverse_lazy
from wsse.server.django.wsse.models import UserSecret
from wsse.client.requests.auth import WSSEAuth
import requests

	def test_auth(self):
		'''
		Perform valid authentication. The user should be authenticated.
		'''
		response = requests.get(self.base_url, auth = self.auth)
		self.assertEqual(response.status_code, status.HTTP_200_OK)

	def test_auth_reuse(self):
		'''
		Reuse the same authentication handler. Both requests should succeed.
		'''
		response_a = requests.get(self.base_url, auth = self.auth)
		response_b = requests.get(self.base_url, auth = self.auth)

		self.assertEqual(response_a.status_code, status.HTTP_200_OK)
		self.assertEqual(response_b.status_code, status.HTTP_200_OK)

	def test_auth_incorrect_password(self):
		'''
		Authneticate with an incorrect password. The authentication should fail.
		'''
		response = requests.get(self.base_url, auth = WSSEAuth('username',
			'!' + self.user_secret.secret))
		self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

	def test_auth_nonexistent_username(self):
		'''
		Authneticate with a nonexistent user. The authentication should fail.
		'''

# Path: wsse/settings.py
# TIMESTAMP_DURATION = 2 * 60 * 60
# DRIFT_OFFSET = 2 * 60
# TIMESTAMP_FORMATS = [
# 	'%Y-%m-%dT%H:%M:%SZ',    # ISO 8601 in UTC (Z specifies 0 offset)
# 	'%Y-%m-%dT%H:%M:%S',     # ISO 8601 without timezone - assumed to be UTC
# 	'%Y-%m-%dT%H:%M:%S.%fZ', # ISO 8601 with microseconds in UTC
# 	'%Y-%m-%dT%H:%M:%S.%f',  # ISO 8601 with microseconds (assumed UTC)
# 	'%Y-%m-%dT%H:%M:%S%z',   # ISO 8601 with UTC offset
# 	'%Y-%m-%dT%H:%M:%S.%f%z' # ISO 8601 with microseconds and UTC offset
# 	]
# NONCE_LENGTH = 64
# NONCE_STORE = 'wsse.server.default.store.SQLiteNonceStore'
# NONCE_STORE_ARGS = (':memory:',)
# REQUEST_HEADER = 'X-WSSE'
# SECURITY_CHECK_NONCE = True
# SECURITY_CHECK_TIMESTAMP = True
# ALLOWED_DIGEST_ALGORITHMS = ['SHA256']
# PROHIBITED_DIGEST_ALGORITHMS = ['SHA1', 'MD5']
# SECRET_KEY_LENGTH = 64
# LOGGER_NAME = 'wsse'
# 
# Path: wsse/compat.py

# 
# Path: wsse/server/django/wsse/models.py
# class UserSecret(models.Model):
# 	'''
# 	The `UserSecret` object connects every user to their secret key. The secret
# 	key can be deleted to prevent access without affecting the user.
# 	'''
# 	user = models.OneToOneField(User, on_delete = models.CASCADE,
# 		db_index = True)
# 	secret = models.CharField(max_length = settings.SECRET_KEY_LENGTH,
# 		default = _generate_secret, blank = True, null = False)
# 
# Path: wsse/client/requests/auth.py
# class WSSEAuth(requests.auth.AuthBase):
# 	'''
# 	Attaches HTTP Digest Authentication to the given Request object.
# 
# 	Usage:
# 		requests.get(url, auth=WSSEAuth(username, password))
# 
# 	The auth object isreusable, and can be defined separately if several
# 	requests will be made with the same username & password pair.
# 
# 	:param username: username to include in request
# 	:type username: str
# 
# 	:param password: password to authenticate with
# 	:type password: str
# 	'''
# 	def __init__(self, username, password):
# 		self.token_builder = utils.TokenBuilder(username, password)
# 
# 	def __call__(self, r):
# 		'''Attach the appropriate request header to attempt WSSE authentication.'''
# 		token = self.token_builder.make_token()
# 		r.headers[settings.REQUEST_HEADER] = token
# 		return r


# Path: wsse/client/requests/tests/test_auth.py
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.contrib.auth.models import User
from rest_framework import status
from wsse import settings
from wsse.compat import reverse_lazy
from wsse.server.django.wsse.models import UserSecret
from wsse.client.requests.auth import WSSEAuth
import requests


	def test_auth(self):
		'''
		Perform valid authentication. The user should be authenticated.
		'''
		response = requests.get(self.base_url, auth = self.auth)
		self.assertEqual(response.status_code, status.HTTP_200_OK)

	def test_auth_reuse(self):
		'''
		Reuse the same authentication handler. Both requests should succeed.
		'''
		response_a = requests.get(self.base_url, auth = self.auth)
		response_b = requests.get(self.base_url, auth = self.auth)

		self.assertEqual(response_a.status_code, status.HTTP_200_OK)
		self.assertEqual(response_b.status_code, status.HTTP_200_OK)

	def test_auth_incorrect_password(self):
		'''
		Authneticate with an incorrect password. The authentication should fail.
		'''
		response = requests.get(self.base_url, auth = WSSEAuth('username',
			'!' + self.user_secret.secret))
		self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

	def test_auth_nonexistent_username(self):
		'''
		Authneticate with a nonexistent user. The authentication should fail.
		'''

		response = requests.get(self.base_url, auth = WSSEAuth('nonexistentuser',