Skip to content

Commit 8389caa

Browse files
committed
Added simple SSL test
1 parent a89cafa commit 8389caa

File tree

8 files changed

+92
-3
lines changed

8 files changed

+92
-3
lines changed

CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Lines starting with '#' are comments.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in the repo.
5+
* @anu3990 @billfarber @rjrudin

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ To run the tests:
1717
- Run `./gradlew -i mlDeploy`
1818
- `cd ..`
1919
- Run `pytest`
20+
21+
To run an individual test with logging to stdout:
22+
23+
pytest -s tests/test_search.py
24+
25+
To run an individual test method:
26+
27+
pytest -s test/test_search.py::test_search

test-app/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
plugins {
22
id 'net.saliman.properties' version '1.5.2'
33
id 'com.marklogic.ml-gradle' version '4.5.2'
4-
}
4+
}
5+
6+
// Generate a temporary certificate for some simple SSL tests
7+
ext {
8+
def command = new com.marklogic.appdeployer.command.security.GenerateTemporaryCertificateCommand()
9+
command.setTemplateIdOrName("python-test-ssl-template")
10+
command.setCommonName("localhost")
11+
command.setValidFor(365)
12+
mlAppDeployer.commands.add(command)
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<certificate-template-properties xmlns="http://marklogic.com/manage">
2+
<template-name>python-test-ssl-template</template-name>
3+
<template-description>Used for marklogic-python-client testing</template-description>
4+
<key-type>rsa</key-type>
5+
<key-options />
6+
<req>
7+
<version>0</version>
8+
<subject>
9+
<countryName>US</countryName>
10+
<stateOrProvinceName>VA</stateOrProvinceName>
11+
<localityName>McLean</localityName>
12+
<organizationName>MarkLogic</organizationName>
13+
<organizationalUnitName>Engineering</organizationalUnitName>
14+
<emailAddress>python@marklogic.com</emailAddress>
15+
</subject>
16+
</req>
17+
</certificate-template-properties>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"user-name": "python-test-user",
3+
"password": "password",
4+
"role": [
5+
"rest-reader",
6+
"rest-writer",
7+
"qconsole-user"
8+
]
9+
}
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"server-name" : "%%NAME%%-ssl",
3+
"group-name" : "Default",
4+
"server-type" : "http",
5+
"enabled" : true,
6+
"root" : "/",
7+
"port" : 8031,
8+
"authentication" : "digestbasic",
9+
"content-database" : "%%DATABASE%%",
10+
"modules-database" : "%%MODULES_DATABASE%%",
11+
"ssl-certificate-template": "python-test-ssl-template",
12+
"url-rewriter": "/MarkLogic/rest-api/rewriter.xml",
13+
"error-handler": "/MarkLogic/rest-api/error-handler.xqy",
14+
"rewrite-resolves-globally": true
15+
}
16+

tests/test_search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from requests.auth import HTTPDigestAuth
33

44

5-
def test_get_search_response_with_no_args():
5+
def test_search():
66
response = requests.get(
7-
"http://localhost:8030/v1/search", auth=HTTPDigestAuth("admin", "admin")
7+
"http://localhost:8030/v1/search",
8+
auth=HTTPDigestAuth("python-test-user", "password")
89
)
910
assert 200 == response.status_code
1011
assert "application/xml; charset=utf-8" == response.headers["Content-type"]

tests/test_ssl.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import requests
2+
3+
4+
def test_verify_false():
5+
"""
6+
The certificate verification in requests is fairly picky; while it's possible to disable
7+
hostname validation, I did not find a way to ask it to not care about self-signed certificates.
8+
So for now, this is just verifying that verify=False works with a MarkLogic app server that is
9+
using a self-signed certificate. In the real world, a customer would have a real certificate and
10+
would configure "verify" to point to that.
11+
"""
12+
response = requests.get(
13+
"https://localhost:8031/v1/search",
14+
auth=("python-test-user", "password"),
15+
verify=False,
16+
headers={"Accept": "application/json"},
17+
)
18+
assert 200 == response.status_code
19+
assert "application/json; charset=utf-8" == response.headers["Content-type"]
20+
data = response.json()
21+
assert (
22+
10 == data["page-length"]
23+
), "Just verifying that a JSON search response is returned"

0 commit comments

Comments
 (0)