Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to support servers that non-https endpoints. #131

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
from hamcrest import calling, is_not, raises

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse
from hamcrest import calling, is_not, raises


def test_one(
client: WebFingerClient,
Expand All @@ -16,7 +17,7 @@ def test_one(

webfinger_response : WebFingerQueryResponse = server.override_webfinger_response(
lambda:
client.perform_webfinger_query(test_id),
client.perform_webfinger_query(server, test_id),
{
test_id : overridden_jrd_json_string
}
Expand Down
12 changes: 6 additions & 6 deletions tests/webfinger/client/4_2__12_follow_redirects.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from hamcrest import equal_to
from multidict import MultiDict

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.protocols.web.traffic import HttpResponse
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse
from hamcrest import equal_to
from multidict import MultiDict


@test
def follow_redirects(
Expand All @@ -16,7 +16,7 @@ def follow_redirects(
webfinger_uri = client.construct_webfinger_uri_for(test_id)
hostname = server.hostname

normal_response = client.perform_webfinger_query(test_id)
normal_response = client.perform_webfinger_query(server, test_id)

# can have any arguments per section 7
redirect_https_uri = f'https://{ hostname }/foo?abc=def&ghi=jkl'
Expand All @@ -25,7 +25,7 @@ def follow_redirects(
jrd_headers = MultiDict([('content-type', 'application/jrd+json')])

overridden_redirect_to_https_response : WebFingerQueryResponse = server.override_http_response(
lambda: client.perform_webfinger_query(test_id),
lambda: client.perform_webfinger_query(server, test_id),
{
webfinger_uri : HttpResponse(301, MultiDict([('location', redirect_https_uri)]).extend(jrd_headers), None ),
redirect_https_uri : HttpResponse( 200, jrd_headers, normal_response.http_request_response_pair.response.payload)
Expand All @@ -34,7 +34,7 @@ def follow_redirects(
assert_that(overridden_redirect_to_https_response, equal_to(normal_response), spec_level=SpecLevel.MUST, interop_level=InteropLevel.PROBLEM)

overridden_redirect_to_http_response : WebFingerQueryResponse = server.override_http_response(
lambda: client.perform_webfinger_query(test_id),
lambda: client.perform_webfinger_query(server, test_id),
{
webfinger_uri : HttpResponse(301, MultiDict([('location', redirect_http_uri)]).extend(jrd_headers), None ),
redirect_http_uri : HttpResponse( 200, jrd_headers, normal_response.http_request_response_pair.response.payload)
Expand Down
3 changes: 2 additions & 1 deletion tests/webfinger/client/4_3__6_accept_example_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse


@test
def accept_example_response(
client: WebFingerClient,
Expand Down Expand Up @@ -37,7 +38,7 @@ def accept_example_response(

webfinger_response : WebFingerQueryResponse = server.override_webfinger_response(
lambda:
client.perform_webfinger_query(test_id),
client.perform_webfinger_query(server, test_id),
{
test_id : overridden_jrd_json_string
}
Expand Down
3 changes: 2 additions & 1 deletion tests/webfinger/client/4_4_1__2_accept_jrds_with_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse


@test
def accept_jrds_with_subject(
client: WebFingerClient,
Expand All @@ -21,7 +22,7 @@ def accept_jrds_with_subject(

with_subject_response = server.override_webfinger_response(
lambda:
client.perform_webfinger_query(test_id),
client.perform_webfinger_query(server, test_id),
{
test_id : json.dumps(json_with_subject)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse


@test
def accept_jrds_without_subject(
client: WebFingerClient,
Expand All @@ -19,7 +20,7 @@ def accept_jrds_without_subject(
json_without_subject.pop('subject')

without_subject_response : WebFingerQueryResponse = server.override_webfinger_response(
lambda: client.perform_webfinger_query(test_id),
lambda: client.perform_webfinger_query(server, test_id),
{
test_id : json.dumps(json_without_subject)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/webfinger/client/4_4__1_rejects_invalid_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse


@test
def rejects_invalid_json(
client: WebFingerClient,
Expand Down Expand Up @@ -36,7 +37,7 @@ def rejects_invalid_json(

webfinger_response : WebFingerQueryResponse = server.override_webfinger_response(
lambda:
client.perform_webfinger_query(test_id),
client.perform_webfinger_query(server, test_id),
{
test_id : overridden_jrd_json_string
}
Expand Down
3 changes: 2 additions & 1 deletion tests/webfinger/client/4_4__2_accept_unknown_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse


@test
def accept_unknown_entries(
client: WebFingerClient,
Expand Down Expand Up @@ -44,7 +45,7 @@ def accept_unknown_entries(

webfinger_response : WebFingerQueryResponse = server.override_webfinger_response(
lambda:
client.perform_webfinger_query(test_id),
client.perform_webfinger_query(server, test_id),
{
test_id : overridden_jrd_json_string
}
Expand Down
8 changes: 4 additions & 4 deletions tests/webfinger/client/4__2_only_https_requests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from hamcrest import equal_to, is_not, all_of

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.utils import uri_parse_validate
from feditest.protocols.web.traffic import HttpResponse, ParsedUri
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.utils import uri_parse_validate
from hamcrest import all_of, equal_to, is_not


@test
def only_https_requests(
Expand All @@ -13,7 +13,7 @@ def only_https_requests(
test_ids =[ server.obtain_account_identifier() ]

responses : list[HttpResponse] = server.transaction(
lambda:[ client.perform_webfinger_query(test_id) for test_id in test_ids ]
lambda:[ client.perform_webfinger_query(server, test_id) for test_id in test_ids ]
).entries()

assert(len(responses) == len(test_ids))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from hamcrest import none

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.protocols import SkipTestException
from feditest.protocols.web import WebClient
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import ClaimedJrd
from feditest.protocols.webfinger.utils import none_except, recursive_equal_to, wf_error
from hamcrest import none

RELS = [
'http://webfinger.net/rel/profile-page',
Expand All @@ -26,7 +25,7 @@ def parameter_ordering(
first_webfinger_response = None
for i in range(0, len(RELS)):
rels = RELS[i:] + RELS[0:i]
webfinger_response = client.perform_webfinger_query(test_id, rels)
webfinger_response = client.perform_webfinger_query(server, test_id, rels)

assert_that(
webfinger_response.exc,
Expand Down
5 changes: 2 additions & 3 deletions tests/webfinger/server/4_2__14_must_only_redirect_to_https.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from hamcrest import equal_to

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import WebFingerQueryResponse
from hamcrest import equal_to


@test
Expand All @@ -15,7 +14,7 @@ def must_only_redirect_to_https(
"""
test_id = server.obtain_account_identifier()

response : WebFingerQueryResponse = client.perform_webfinger_query(test_id)
response : WebFingerQueryResponse = client.perform_webfinger_query(server, test_id)
assert_that(
response.http_request_response_pair.final_request.uri.scheme,
equal_to('https'),
Expand Down
6 changes: 3 additions & 3 deletions tests/webfinger/server/4_2__2_perform_query.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from hamcrest import none, not_none

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.utils import wf_error
from hamcrest import none, not_none


@test
def normal_query(
Expand All @@ -14,7 +14,7 @@ def normal_query(
"""
test_id = server.obtain_account_identifier()

webfinger_response = client.perform_webfinger_query(test_id)
webfinger_response = client.perform_webfinger_query(server, test_id)

assert_that(
webfinger_response.exc,
Expand Down
15 changes: 9 additions & 6 deletions tests/webfinger/server/4__1_accepts_all_link_rels_in_query.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from hamcrest import none

from feditest import InteropLevel, SpecLevel, assert_that, test
from feditest.protocols import SkipTestException
from feditest.protocols.web import WebClient
from feditest.protocols.webfinger import WebFingerClient, WebFingerServer
from feditest.protocols.webfinger.traffic import ClaimedJrd, WebFingerQueryResponse
from feditest.protocols.webfinger.utils import link_subset_or_equal_to, none_except, wf_error
from feditest.protocols.webfinger.utils import (
link_subset_or_equal_to,
none_except,
wf_error,
)
from feditest.reporting import info
from hamcrest import none

# Note: we do not try all the known rel values, only the ones known to be used in a webfinger context
# See also https://fedidevs.org/reference/webfinger/
Expand Down Expand Up @@ -58,7 +61,7 @@ def accepts_known_link_rels_in_query(
Tests one known link rel at a time.
"""
test_id = server.obtain_account_identifier()
response_without_rel : WebFingerQueryResponse = client.perform_webfinger_query(test_id)
response_without_rel = client.perform_webfinger_query(server, test_id)
if ( response_without_rel.exc
and response_without_rel.exc in (WebClient.WrongContentTypeError, ClaimedJrd.InvalidMediaTypeError, ClaimedJrd.InvalidRelError)
):
Expand Down Expand Up @@ -100,7 +103,7 @@ def accepts_unknown_link_rels_in_query(
"""
test_id = server.obtain_account_identifier()

response_without_rel = client.perform_webfinger_query(test_id)
response_without_rel = client.perform_webfinger_query(server, test_id)
if ( response_without_rel.exc
and response_without_rel.exc in (WebClient.WrongContentTypeError, ClaimedJrd.InvalidMediaTypeError, ClaimedJrd.InvalidRelError)
):
Expand Down Expand Up @@ -141,7 +144,7 @@ def accepts_combined_link_rels_in_query(
"""
test_id = server.obtain_account_identifier()

response_without_rel = client.perform_webfinger_query(test_id)
response_without_rel = client.perform_webfinger_query(server, test_id)
if ( response_without_rel.exc
and response_without_rel.exc in (WebClient.WrongContentTypeError, ClaimedJrd.InvalidMediaTypeError, ClaimedJrd.InvalidRelError)
):
Expand Down
2 changes: 1 addition & 1 deletion tests/webfinger/server/5_1_cors_header_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def cors_header_required(
"""
test_id = server.obtain_account_identifier()

pair : HttpRequestResponsePair = client.perform_webfinger_query(test_id).http_request_response_pair
pair = client.perform_webfinger_query(server, test_id).http_request_response_pair

assert_that(
'access-control-allow-origin' in pair.response.response_headers,
Expand Down