def test_query():
    rel = 'http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fissuer'
    pattern = 'https://{}/.well-known/webfinger?rel={}&resource={}'
    example_oidc = {
        'example.com': ('example.com', rel, 'acct%3Aexample.com'),
        '*****@*****.**': ('example.com', rel, 'acct%3Ajoe%40example.com'),
        'example.com/joe':
        ('example.com', rel, 'https%3A%2F%2Fexample.com%2Fjoe'),
        'example.com:8080':
        ('example.com:8080', rel, 'https%3A%2F%2Fexample.com%3A8080'),
        '*****@*****.**':
        ('example.com', rel, 'acct%3AJane.Doe%40example.com'),
        '[email protected]:8080': ('[email protected]:8080', rel,
                                   'https%3A%2F%2Falice%40example.com%3A8080'),
        'https://example.com': ('example.com', rel,
                                'https%3A%2F%2Fexample.com'),
        'https://example.com/joe': ('example.com', rel,
                                    'https%3A%2F%2Fexample.com%2Fjoe'),
        'https://[email protected]:8080':
        ('[email protected]:8080', rel,
         'https%3A%2F%2Fjoe%40example.com%3A8080'),
        'acct:[email protected]': ('example.com', rel,
                                 'acct%3Ajoe%40example.com')
    }

    wf = WebFinger(SERVICE_CONTEXT)
    for key, args in example_oidc.items():
        _q = wf.query(key)
        p = urlsplit(_q)
        assert p.netloc == args[0]
        qs = parse_qs(p.query)
        assert qs['resource'][0] == unquote_plus(args[2])
        assert qs['rel'][0] == unquote_plus(args[1])
예제 #2
0
def test_query():
    rel = 'http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fissuer'
    pattern = 'https://{}/.well-known/webfinger?rel={}&resource={}'
    example_oidc = {
        'example.com': ('example.com', rel, 'acct%3Aexample.com'),
        '*****@*****.**': ('example.com', rel, 'acct%3Ajoe%40example.com'),
        'example.com/joe':
        ('example.com', rel, 'https%3A%2F%2Fexample.com%2Fjoe'),
        'example.com:8080':
        ('example.com:8080', rel, 'https%3A%2F%2Fexample.com%3A8080'),
        '*****@*****.**':
        ('example.com', rel, 'acct%3AJane.Doe%40example.com'),
        '[email protected]:8080': ('[email protected]:8080', rel,
                                   'https%3A%2F%2Falice%40example.com%3A8080'),
        'https://example.com': ('example.com', rel,
                                'https%3A%2F%2Fexample.com'),
        'https://example.com/joe': ('example.com', rel,
                                    'https%3A%2F%2Fexample.com%2Fjoe'),
        'https://[email protected]:8080':
        ('[email protected]:8080', rel,
         'https%3A%2F%2Fjoe%40example.com%3A8080'),
        'acct:[email protected]': ('example.com', rel,
                                 'acct%3Ajoe%40example.com')
    }

    wf = WebFinger(None, None)
    for key, args in example_oidc.items():
        _q = wf.query(key)
        assert _q == pattern.format(*args)
예제 #3
0
 def test_query_rel(self):
     wf = WebFinger(SERVICE_CONTEXT, state_db=None)
     request_args = {'resource': "acct:[email protected]"}
     _info = wf.get_request_parameters(request_args)
     assert _info['url'] == \
            "https://example.com/.well-known/webfinger?rel=http%3A%2F%2Fopenid" \
            ".net%2Fspecs%2Fconnect%2F1.0%2Fissuer&resource=acct%3Abob" \
            "%40example.com"
 def test_query_rel(self):
     wf = WebFinger(SERVICE_CONTEXT)
     request_args = {'resource': "acct:[email protected]"}
     _info = wf.get_request_parameters(request_args)
     p = urlsplit(_info['url'])
     assert p.netloc == "example.com"
     qs = parse_qs(p.query)
     assert qs['resource'][0] == "acct:[email protected]"
     assert qs['rel'][0] == "http://openid.net/specs/connect/1.0/issuer"
예제 #5
0
 def test_query_device(self):
     wf = WebFinger(SERVICE_CONTEXT, state_db=None)
     request_args = {'resource': "p1.example.com"}
     _info = wf.get_request_parameters(request_args)
     assert _info[
                'url'] == 'https://p1.example.com/.well-known/webfinger' \
                          '?rel=http%3A%2F' \
                          '%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fissuer' \
                          '&resource=acct%3Ap1.example.com'
    def test_query_acct_no_resource(self):
        wf = WebFinger(SERVICE_CONTEXT, rel=OIC_ISSUER)
        try:
            del wf.service_context.config['resource']
        except KeyError:
            pass
        request_args = {}

        with pytest.raises(MissingRequiredAttribute):
            wf.get_request_parameters(request_args=request_args)
예제 #7
0
    def test_query_acct_resource_config(self):
        wf = WebFinger(SERVICE_CONTEXT, rel=OIC_ISSUER, state_db=None)
        wf.service_context.config['resource'] = "acct:[email protected]"
        request_args = {}
        _info = wf.get_request_parameters(request_args=request_args)

        assert _info['url'] == \
               "https://example.com/.well-known/webfinger?rel=http%3A%2F%2Fopenid" \
               ".net%2Fspecs%2Fconnect%2F1.0%2Fissuer&resource" \
               "=acct%3Acarol%40example.com"
    def test_query_acct_resource_config(self):
        wf = WebFinger(SERVICE_CONTEXT, rel=OIC_ISSUER)
        wf.service_context.config['resource'] = "acct:[email protected]"
        request_args = {}
        _info = wf.get_request_parameters(request_args=request_args)

        p = urlsplit(_info['url'])
        assert p.netloc == "example.com"
        qs = parse_qs(p.query)
        assert qs['resource'][0] == "acct:[email protected]"
        assert qs['rel'][0] == "http://openid.net/specs/connect/1.0/issuer"
def test_query_2():
    rel = 'http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fissuer'
    pattern = 'https://{}/.well-known/webfinger?rel={}&resource={}'
    example_oidc = {
        # below are identifiers that are slightly off
        "example.com?query": ('example.com', rel,
                              'https%3A%2F%2Fexample.com%3Fquery'),
        "example.com#fragment": ('example.com', rel,
                                 'https%3A%2F%2Fexample.com'),
        "example.com:8080/path?query#fragment":
        ('example.com:8080', rel,
         'https%3A%2F%2Fexample.com%3A8080%2Fpath%3Fquery'),
        "http://example.com/path": ('example.com', rel,
                                    'http%3A%2F%2Fexample.com%2Fpath'),
        "http://example.com?query": ('example.com', rel,
                                     'http%3A%2F%2Fexample.com%3Fquery'),
        "http://example.com#fragment": ('example.com', rel,
                                        'http%3A%2F%2Fexample.com'),
        "http://example.com:8080/path?query#fragment":
        ('example.com:8080', rel,
         'http%3A%2F%2Fexample.com%3A8080%2Fpath%3Fquery'),
        "[email protected]:8080": ("[email protected]:8080", rel,
                                 "https%3A%2F%2Fnov%40example.com%3A8080"),
        "[email protected]/path": ("*****@*****.**", rel,
                                 "https%3A%2F%2Fnov%40example.com%2Fpath"),
        "[email protected]?query": ("*****@*****.**", rel,
                                  "https%3A%2F%2Fnov%40example.com%3Fquery"),
        "[email protected]#fragment": ("*****@*****.**", rel,
                                     "https%3A%2F%2Fnov%40example.com"),
        "[email protected]:8080/path?query#fragment":
        ("[email protected]:8080", rel,
         "https%3A%2F%2Fnov%40example.com%3A8080%2Fpath%3Fquery"),
        "acct:[email protected]:8080": ("example.com:8080", rel,
                                      "acct%3Anov%40example.com%3A8080"),
        "acct:[email protected]/path": ("example.com", rel,
                                      "acct%3Anov%40example.com%2Fpath"),
        "acct:[email protected]?query": ("example.com", rel,
                                       "acct%3Anov%40example.com%3Fquery"),
        "acct:[email protected]#fragment": ("example.com", rel,
                                          "acct%3Anov%40example.com"),
        "acct:[email protected]:8080/path?query#fragment":
        ("example.com:8080", rel,
         "acct%3Anov%40example.com%3A8080%2Fpath%3Fquery")
    }

    wf = WebFinger(SERVICE_CONTEXT)
    for key, args in example_oidc.items():
        _q = wf.query(key)
        p = urlsplit(_q)
        assert p.netloc == args[0]
        qs = parse_qs(p.query)
        assert qs['resource'][0] == unquote_plus(args[2])
        assert qs['rel'][0] == unquote_plus(args[1])
예제 #10
0
def test_query_2():
    rel = 'http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fissuer'
    pattern = 'https://{}/.well-known/webfinger?rel={}&resource={}'
    example_oidc = {
        # below are identifiers that are slightly off
        "example.com?query": ('example.com', rel,
                              'https%3A%2F%2Fexample.com%3Fquery'),
        "example.com#fragment": ('example.com', rel,
                                 'https%3A%2F%2Fexample.com'),
        "example.com:8080/path?query#fragment":
        ('example.com:8080', rel,
         'https%3A%2F%2Fexample.com%3A8080%2Fpath%3Fquery'),
        "http://example.com/path": ('example.com', rel,
                                    'http%3A%2F%2Fexample.com%2Fpath'),
        "http://example.com?query": ('example.com', rel,
                                     'http%3A%2F%2Fexample.com%3Fquery'),
        "http://example.com#fragment": ('example.com', rel,
                                        'http%3A%2F%2Fexample.com'),
        "http://example.com:8080/path?query#fragment":
        ('example.com:8080', rel,
         'http%3A%2F%2Fexample.com%3A8080%2Fpath%3Fquery'),
        "[email protected]:8080": ("[email protected]:8080", rel,
                                 "https%3A%2F%2Fnov%40example.com%3A8080"),
        "[email protected]/path": ("*****@*****.**", rel,
                                 "https%3A%2F%2Fnov%40example.com%2Fpath"),
        "[email protected]?query": ("*****@*****.**", rel,
                                  "https%3A%2F%2Fnov%40example.com%3Fquery"),
        "[email protected]#fragment": ("*****@*****.**", rel,
                                     "https%3A%2F%2Fnov%40example.com"),
        "[email protected]:8080/path?query#fragment":
        ("[email protected]:8080", rel,
         "https%3A%2F%2Fnov%40example.com%3A8080%2Fpath%3Fquery"),
        "acct:[email protected]:8080": ("example.com:8080", rel,
                                      "acct%3Anov%40example.com%3A8080"),
        "acct:[email protected]/path": ("example.com", rel,
                                      "acct%3Anov%40example.com%2Fpath"),
        "acct:[email protected]?query": ("example.com", rel,
                                       "acct%3Anov%40example.com%3Fquery"),
        "acct:[email protected]#fragment": ("example.com", rel,
                                          "acct%3Anov%40example.com"),
        "acct:[email protected]:8080/path?query#fragment":
        ("example.com:8080", rel,
         "acct%3Anov%40example.com%3A8080%2Fpath%3Fquery")
    }

    wf = WebFinger(None, None)
    for key, args in example_oidc.items():
        _q = wf.query(key)
        assert _q == pattern.format(*args)