-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Set Environment Variables | ||
os.environ["AUTH_USER"] = "testuser" | ||
os.environ["AUTH_PASS"] = "testpass" | ||
|
||
import pytest | ||
import os | ||
from app import app as flask_app | ||
|
||
@pytest.fixture | ||
def app(): | ||
yield flask_app | ||
|
||
@pytest.fixture | ||
def client(app): | ||
return app.test_client() |
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,36 @@ | ||
import base64 | ||
import os | ||
|
||
def test_env_vars(): | ||
assert os.environ["AUTH_USER"] == "testuser" | ||
assert os.environ["AUTH_PASS"] == "testpass" | ||
|
||
def basic_auth(username, password): | ||
credentials = f"{username}:{password}" | ||
auth_header = base64.b64encode(credentials.encode()).decode('utf-8') | ||
return {'Authorization': f'Basic {auth_header}'} | ||
|
||
def test_good_auth(app, client): | ||
auth_headers = basic_auth('testuser', 'testpass') | ||
res = client.get('/update?hostname=test.domain.com&ip=0.0.0.0', headers=auth_headers) | ||
assert b'noapitoken' in res.data | ||
assert res.status_code == 200 | ||
|
||
def test_bad_auth(app, client): | ||
auth_headers = basic_auth('testuser', 'badpass') | ||
res = client.get('/update?hostname=test.domain.com&ip=0.0.0.0', headers=auth_headers) | ||
assert b'badauth' in res.data | ||
assert res.status_code == 401 | ||
|
||
|
||
def test_missing_hostname(app, client): | ||
auth_headers = basic_auth('testuser', 'testpass') | ||
res = client.get('/update?ip=0.0.0.0', headers=auth_headers) | ||
assert b'nohost' in res.data | ||
assert res.status_code == 200 | ||
|
||
def test_missing_ip(app, client): | ||
auth_headers = basic_auth('testuser', 'testpass') | ||
res = client.get('/update?hostname=test.domain.com', headers=auth_headers) | ||
assert b'noip' in res.data | ||
assert res.status_code == 200 |