コード例 #1
0
def test_cyclic_roles():
    res = Resolver({
        "test-client-1": ["assume:test-role"],
        "test-role": ["special-scope", "assume:test-client-1"],
    })
    check_resolved(
        res,
        ["assume:test-client-1"],
        ["assume:test-client-1", "assume:test-role", "special-scope"],
    )
コード例 #2
0
def test_from_resources():
    resources = Resources(
        resources=[
            Role(roleId="role1", description="1", scopes=["one"]),
            Role(roleId="role2", description="2", scopes=["two"]),
        ],
        managed=["Role=role*"],
    )
    res = Resolver.from_resources(resources)
    assert sorted(res.expandScopes(["assume:role1"
                                    ])) == ["assume:role1", "one"]
コード例 #3
0
def test_parameterized_simple_claim_task():
    res = Resolver({"worker-type:*": ["queue:claim-task:<..>"]})
    check_resolved(
        res,
        ["assume:worker-type:prov1/wt2"],
        ["assume:worker-type:prov1/wt2", "queue:claim-task:prov1/wt2"],
    )
    check_resolved(
        res,
        ["assume:worker-type:prov1/*"],
        ["assume:worker-type:prov1/*", "queue:claim-task:prov1/*"],
    )
コード例 #4
0
def test_many_indirect_roles():
    roles = {
        "test-role-{}".format(n): ["assume:test-role-{}".format(n + 1)]
        for n in range(1, 10)
    }
    roles["test-role-10"] = ["special-scope"]
    res = Resolver(roles)
    check_resolved(
        res,
        ["assume:test-role-1"],
        ["assume:test-role-{}".format(n)
         for n in range(1, 11)] + ["special-scope"],
    )
コード例 #5
0
def test_expand_star_in_initial_scopes():
    res = Resolver({
        "repo:hg.mozilla.org/comm-central:cron:nightly-*": [
            "assume:project:comm:thunderbird:comm:releng:nightly:level-3:comm-central"
        ],
        "project:comm:thunderbird:comm:releng:nightly:level-3:comm-central":
        ["comm-stuff"],
    })
    check_resolved(
        res,
        ["assume:repo:hg.mozilla.org/comm-central:cron:*"],
        [
            "assume:repo:hg.mozilla.org/comm-central:cron:*",
            "assume:project:comm:thunderbird:comm:releng:nightly:level-3:comm-central",
            "comm-stuff",
        ],
    )
コード例 #6
0
def test_parameterized_project_admin():
    res = Resolver({
        "project-admin:*": [
            "auth:create-client:project/<..>/*",
            "assume:project:<..>:*",
            "assume:hook-id:project-<..>/*",
        ]
    })
    check_resolved(
        res,
        ["assume:project-admin:pocket"],
        [
            "assume:hook-id:project-pocket/*",
            "assume:project-admin:pocket",
            "assume:project:pocket:*",
            "auth:create-client:project/pocket/*",
        ],
    )
コード例 #7
0
def test_normalizeScopes_with_stars():
    res = Resolver({})
    check_resolved(
        res,
        [
            "assume:hook-id:garbage/*",
            "assume:hook-id:project-*",
            "assume:hook-id:project-<..>/*",
            "assume:hook-id:project-releng/services-master-*",
            "assume:hook-id:project-releng/services-production-*",
            "assume:hook-id:project-releng/services-testing-*",
            "assume:hook-id:tc-hooks-tests/tc-test-hook",
        ],
        [
            "assume:hook-id:garbage/*",
            "assume:hook-id:project-*",
            "assume:hook-id:tc-hooks-tests/tc-test-hook",
        ],
    )
コード例 #8
0
def test_parameterized_scope_escalation():
    res = Resolver({
        "project:taskcluster:docs-upload:*":
        ["auth:aws-s3:read-write:tc-metadata-<..>/docs"]
    })
    check_resolved(
        res,
        ["assume:project:taskcluster:docs-upload:queue"],
        [
            "assume:project:taskcluster:docs-upload:queue",
            "auth:aws-s3:read-write:tc-metadata-queue/docs",  # looks good..
        ],
    )

    check_resolved(
        res,
        ["assume:project:taskcluster:docs-upload:*"],
        [
            "assume:project:taskcluster:docs-upload:*",
            "auth:aws-s3:read-write:tc-metadata-*",  # SURPRISE!
        ],
    )
コード例 #9
0
def test_assume_can_get_star():
    res = Resolver({"thing-id:*": ["*"]})
    check_resolved(res, ["assume:thing-id:test"], ["*"])
コード例 #10
0
def test_assume_thing_star():
    res = Resolver({"thing-id:*": ["test-scope-1"]})
    check_resolved(res, ["assume:thing-id:test"],
                   ["assume:thing-id:test", "test-scope-1"])
コード例 #11
0
def test_expand_role_star():
    res = Resolver({"role*": ["rstar"], "role2": ["r2a", "r2b"]})
    check_resolved(res, ["aa", "assume:role2"],
                   ["aa", "assume:role2", "rstar", "r2a", "r2b"])
コード例 #12
0
def test_expand_star():
    res = Resolver({"role1": ["r1a", "r1b"], "role2": ["r2a", "r2b"]})
    check_resolved(res, ["aa", "assume:role*"],
                   ["aa", "assume:role*", "r1a", "r1b", "r2a", "r2b"])
コード例 #13
0
def test_expand_simple():
    res = Resolver({"role1": ["r1a", "r1b"]})
    check_resolved(res, ["aa", "assume:role1"],
                   ["aa", "assume:role1", "r1a", "r1b"])
コード例 #14
0
def test_identity():
    res = Resolver({})
    check_resolved(res, ["aa", "bb"], ["aa", "bb"])
コード例 #15
0
def test_parameterized_star_in_replacement():
    res = Resolver({"A*": ["assume:B<..>C"]})
    check_resolved(res, ["assume:Abc*"], ["assume:Abc*", "assume:Bbc*"])
コード例 #16
0
def resolver(auth):
    roles = auth.listRoles()
    return Resolver({r["roleId"]: r["scopes"] for r in roles})
コード例 #17
0
def test_assumestar_means_assume():
    res = Resolver({"test-1": ["assume*"], "foo": ["bar"]})
    check_resolved(res, ["assume:test-1"], ["assume*", "bar"])