def test_verify_project_invalid_context(self): verifier = pretend.stub(context=pretend.stub()) caveat = V1Caveat(verifier) predicate = {"version": 1, "permissions": {"projects": ["notfoobar"]}} with pytest.raises(InvalidMacaroon): caveat(json.dumps(predicate))
def test_verify_project(self, db_request): project = ProjectFactory.create(name="foobar") verifier = pretend.stub(context=project) caveat = V1Caveat(verifier) predicate = {"version": 1, "permissions": {"projects": ["foobar"]}} assert caveat(json.dumps(predicate)) is True
def test_verify_project_invalid_context(self): verifier = pretend.stub(context=pretend.stub()) caveat = V1Caveat(verifier) predicate = {"version": 1, "permissions": {"projects": ["notfoobar"]}} assert caveat(json.dumps(predicate)) is False
def test_verify_project_invalid_project_name(self, db_request): project = ProjectFactory.create(name="foobar") verifier = pretend.stub(context=project) caveat = V1Caveat(verifier) predicate = {"version": 1, "permissions": {"projects": ["notfoobar"]}} with pytest.raises(InvalidMacaroon): caveat(json.dumps(predicate))
def test_verify_project_no_projects_object(self, db_request): project = ProjectFactory.create(name="foobar") verifier = pretend.stub(context=project) caveat = V1Caveat(verifier) predicate = { "version": 1, "permissions": {"somethingthatisntprojects": ["blah"]}, } with pytest.raises(InvalidMacaroonError): caveat(json.dumps(predicate))
def test_verify_project_no_projects_object(self, db_request): project = ProjectFactory.create(name="foobar") verifier = pretend.stub(context=project) caveat = V1Caveat(verifier) predicate = { "version": 1, "permissions": { "somethingthatisntprojects": ["blah"] }, } assert caveat(json.dumps(predicate)) is False
def test_verify_valid_predicate(self): verifier = pretend.stub() caveat = V1Caveat(verifier) predicate = '{"permissions": "user", "version": 1}' assert caveat(predicate) is True
def test_verify_invalid_predicates(self, predicate, result): verifier = pretend.stub() caveat = V1Caveat(verifier) assert caveat(predicate) is False
def test_verify_invalid_predicates(self, predicate, result): verifier = pretend.stub() caveat = V1Caveat(verifier) with pytest.raises(InvalidMacaroon): caveat(predicate)