8000 htpasswd tests · nginx-proxy/nginx-proxy@a9f8a9c · GitHub
[go: up one dir, main page]

Skip to content

Commit a9f8a9c

Browse files
SchoNiebuchdag
authored andcommitted
htpasswd tests
1 parent da00655 commit a9f8a9c

6 files changed

+63
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vhost:$2a$13$/aPYmoK0mmgyAI4TpKdFY.6441Ugo39MdXjhpm.Pp6D15rbz9tvz.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vpath:$2a$13$/aPYmoK0mmgyAI4TpKdFY.6441Ugo39MdXjhpm.Pp6D15rbz9tvz.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
3+
def test_htpasswd_virtual_host_is_restricted(docker_compose, nginxproxy):
4+
r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/port")
5+
assert r.status_code == 401
6+
assert "WWW-Authenticate" in r.headers
7+
assert r.headers["WWW-Authenticate"] == 'Basic realm="Restricted htpasswd.nginx-proxy.tld"'
8+
9+
10+
def test_htpasswd_virtual_host_basic_auth(docker_compose, nginxproxy):
11+
r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/port", auth=("vhost", "password"))
12+
assert r.status_code == 200
13+
assert r.text == "answer from port 80\n"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "2"
2+
3+
services:
4+
web:
5+
image: web
6+
expose:
7+
- "80"
8+
environment:
9+
WEB_PORTS: 80
10+
VIRTUAL_HOST: htpasswd.nginx-proxy.tld
11+
12+
sut:
13+
container_name: sut
14+
image: nginxproxy/nginx-proxy:test
15+
volumes:
16+
- /var/run/docker.sock:/tmp/docker.sock:ro
17+
- ./htpasswd:/etc/nginx/htpasswd:ro
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
def test_htpasswd_virtual_path_is_restricted(docker_compose, nginxproxy):
4+
r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/foo/port")
5+
assert r.status_code == 401
6+
assert "WWW-Authenticate" in r.headers
7+
assert r.headers["WWW-Authenticate"] == 'Basic realm="Restricted htpasswd.nginx-proxy.tld/foo/"'
8+
9+
def test_htpasswd_virtual_path_basic_auth(docker_compose, nginxproxy):
10+
r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/foo/port", auth=("vpath", "password"))
11+
assert r.status_code == 200
12+
assert r.text == "answer from port 80\n"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "2"
2+
3+
services:
4+
web:
5+
image: web
6+
expose:
7+
- "80"
8+
environment:
9+
WEB_PORTS: 80
10+
VIRTUAL_HOST: htpasswd.nginx-proxy.tld
11+
VIRTUAL_PATH: /foo/
12+
VIRTUAL_DEST: /
13+
14+
sut:
15+
container_name: sut
16+
image: nginxproxy/nginx-proxy:test
17+
volumes:
18+
- /var/run/docker.sock:/tmp/docker.sock:ro
19+
- ./htpasswd:/etc/nginx/htpasswd:ro

0 commit comments

Comments
 (0)
0