def test_logs_rejection(self): self.create_mock('beachfront.middleware.ENFORCE_HTTPS', new=True) self.request.is_secure = False middleware.https_filter() self.assertEqual([ 'WARNING - Rejecting non-HTTPS request: endpoint=`/test-path` referrer=`http://test-referrer`', ], self.logger.lines)
def test_when_enabled_allows_https_requests(self): self.create_mock('beachfront.middleware.ENFORCE_HTTPS', new=True) self.request.is_secure = True response = middleware.https_filter() self.assertIsNone(response)
def test_when_enabled_rejects_non_https_requests(self): self.create_mock('beachfront.middleware.ENFORCE_HTTPS', new=True) self.request.is_secure = False response = middleware.https_filter() self.assertEqual(('Access Denied: Please retry with HTTPS', 403), response)