Esempio n. 1
0
def test_alice_client_read():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com")

    body = json.dumps({"bar": "soap"})

    environ = {
        "REQUEST_METHOD": "GET",
        "REMOTE_USER": "******",
        'wsgi.input': StringIO(body),
        "CONTENT_LENGTH": len(body)
    }
    ad = AuthzDescription(resource_set_id=0,
                          scopes=DEF_SCOPES,
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(
        valid=True,
        expires_at=epoch_in_a_while(minutes=45),
        issued_at=utc_time_sans_frac,
        permissions=[ad]
    )

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert not isinstance(resp, ErrorResponse)
    assert isinstance(resp, Response)
Esempio n. 2
0
def test_roger_patch(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource/")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com")
    create_alice_resource(jrs)

    body = json.dumps({"bar": "soap"})

    environ = {
        "REQUEST_METHOD": "PATCH",
        "REMOTE_USER": "******",
        'wsgi.input': StringIO(body),
        "CONTENT_LENGTH": len(body)
    }
    ad = AuthzDescription(resource_set_id=0,
                          scopes=[
                              "http://dirg.org.umu.se/uma/scopes/read",
                              "http://dirg.org.umu.se/uma/scopes/patch"
                          ],
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(
        valid=True,
        expires_at=epoch_in_a_while(minutes=45),
        issued_at=utc_time_sans_frac,
        permissions=[ad]
    )

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert not isinstance(resp, ErrorResponse)
    assert resp.message == '{"_id": "1"}'
Esempio n. 3
0
def test_roger_create():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com")

    body = json.dumps({"bar": "soap"})

    environ = {
        "REQUEST_METHOD": "POST",
        "REMOTE_USER": "******",
        'wsgi.input': StringIO(body),
        "CONTENT_LENGTH": len(body)
    }
    ad = AuthzDescription(resource_set_id=0,
                          scopes=["http://dirg.org.umu.se/uma/scopes/read"],
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(
        valid=True,
        expires_at=epoch_in_a_while(minutes=45),
        issued_at=utc_time_sans_frac,
        permissions=[ad]
    )

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert isinstance(resp, ErrorResponse)
Esempio n. 4
0
def test_get_owner(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource/")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com",
                             ["alice"])
    jrs.index["alice"] = 1
    assert jrs.get_owner("info/alice/1") == "alice"
    assert jrs.get_owner("info/public/x") is None
Esempio n. 5
0
def test_get_owner(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource/")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com",
                             ["alice"])
    jrs.index["alice"] = 1
    assert jrs.get_owner("info/alice/1") == "alice"
    assert jrs.get_owner("info/public/x") is None
Esempio n. 6
0
def test_alice_client_read(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource/")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com")
    create_alice_resource(jrs)

    body = json.dumps({"bar": "soap"})

    environ = {
        "REQUEST_METHOD": "GET",
        "REMOTE_USER": "******",
        'wsgi.input': StringIO(body),
        "CONTENT_LENGTH": len(body)
    }
    ad = AuthzDescription(resource_set_id=0,
                          scopes=DEF_SCOPES,
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(valid=True,
                               expires_at=epoch_in_a_while(minutes=45),
                               issued_at=utc_time_sans_frac,
                               permissions=[ad])

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert not isinstance(resp, ErrorResponse)
    assert isinstance(resp, Response)
Esempio n. 7
0
def test_roger_patch(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource/")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com")
    create_alice_resource(jrs)

    body = json.dumps({"bar": "soap"})

    environ = {
        "REQUEST_METHOD": "PATCH",
        "REMOTE_USER": "******",
        'wsgi.input': StringIO(body),
        "CONTENT_LENGTH": len(body)
    }
    ad = AuthzDescription(resource_set_id=0,
                          scopes=[
                              "http://dirg.org.umu.se/uma/scopes/read",
                              "http://dirg.org.umu.se/uma/scopes/patch"
                          ],
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(valid=True,
                               expires_at=epoch_in_a_while(minutes=45),
                               issued_at=utc_time_sans_frac,
                               permissions=[ad])

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert not isinstance(resp, ErrorResponse)
    assert resp.message == '{"_id": "1"}'
Esempio n. 8
0
def test_alice_add():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com")

    body = json.dumps({"foo": "bar"})

    environ = {"REQUEST_METHOD": "POST", "REMOTE_USER": "******",
               'wsgi.input': StringIO(body),
               "CONTENT_LENGTH": len(body)}

    user = "******"
    resp = jrs.do("info/alice", environ, user=user)

    assert not isinstance(resp, ErrorResponse)
Esempio n. 9
0
def test_roger_read():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com")

    environ = {"REQUEST_METHOD": "GET", "REMOTE_USER": "******"}
    ad = AuthzDescription(resource_set_id=0,
                          scopes=["http://dirg.org.umu.se/uma/scopes/read"],
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(
        valid=True,
        expires_at=epoch_in_a_while(minutes=45),
        issued_at=utc_time_sans_frac,
        permissions=[ad]
    )

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert not isinstance(resp, ErrorResponse)
    assert resp.message == '{"foo": "bar", "_id": 1}'
Esempio n. 10
0
def test_roger_read(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource/")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com")

    create_alice_resource(jrs)

    environ = {"REQUEST_METHOD": "GET", "REMOTE_USER": "******"}
    ad = AuthzDescription(resource_set_id=0,
                          scopes=["http://dirg.org.umu.se/uma/scopes/read"],
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(valid=True,
                               expires_at=epoch_in_a_while(minutes=45),
                               issued_at=utc_time_sans_frac,
                               permissions=[ad])

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert not isinstance(resp, ErrorResponse)
    assert resp.message in [
        '{"foo": "bar", "_id": 1}', '{"_id": 1, "foo": "bar"}'
    ]
Esempio n. 11
0
def test_roger_create():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com")

    body = json.dumps({"bar": "soap"})

    environ = {
        "REQUEST_METHOD": "POST",
        "REMOTE_USER": "******",
        'wsgi.input': StringIO(body),
        "CONTENT_LENGTH": len(body)
    }
    ad = AuthzDescription(resource_set_id=0,
                          scopes=["http://dirg.org.umu.se/uma/scopes/read"],
                          expires_at=epoch_in_a_while(minutes=45))

    ir = IntrospectionResponse(valid=True,
                               expires_at=epoch_in_a_while(minutes=45),
                               issued_at=utc_time_sans_frac,
                               permissions=[ad])

    resp = jrs.do("info/alice/1", environ, permission=ir)

    assert isinstance(resp, ErrorResponse)
Esempio n. 12
0
def test_get_owner():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com",
                             ["alice"])
    jrs.index["alice"] = 1
    assert jrs.get_owner("info/alice/1") == "alice"
    assert jrs.get_owner("info/public/x") is None
Esempio n. 13
0
def test_alice_add(tmpdir):
    root_dir = os.path.join(tmpdir.strpath, "resource")
    jrs = JsonResourceServer(root_dir, "info/", "https://example.com")

    resp = create_alice_resource(jrs)
    assert not isinstance(resp, ErrorResponse)
Esempio n. 14
0
def test_init():
    jrs = JsonResourceServer("resource/", "info/", "https://example.com")
    assert jrs