def test_validate_jwt_svid_invalid_input(test_input_token, test_input_audience, expected): with pytest.raises(ArgumentError) as exception: WORKLOAD_API_CLIENT.validate_jwt_svid( token=test_input_token, audience=test_input_audience, ) assert str(exception.value) == expected
def test_validate_jwt_svid_raise_error(mocker): jwt_svid = create_jwt() WORKLOAD_API_CLIENT._spiffe_workload_api_stub.ValidateJWTSVID = mocker.Mock( side_effect=Exception('Mocked error')) with pytest.raises(ValidateJwtSvidError) as exception: WORKLOAD_API_CLIENT.validate_jwt_svid(token=jwt_svid, audience='audience') assert str(exception.value) == 'JWT SVID is not valid: Mocked error.'
def test_validate_jwt_svid(mocker): audience = 'spire' spiffe_id = 'spiffe://test.com/my_service' jwt_svid = create_jwt(audience=[audience], spiffe_id=spiffe_id) WORKLOAD_API_CLIENT._spiffe_workload_api_stub.ValidateJWTSVID = mocker.Mock( return_value=workload_pb2.ValidateJWTSVIDResponse(spiffe_id=spiffe_id, )) svid = WORKLOAD_API_CLIENT.validate_jwt_svid(token=jwt_svid, audience=audience) assert svid.spiffe_id == SpiffeId.parse(spiffe_id) assert svid.token == jwt_svid assert svid.claims['aud'] == [audience] assert svid.audience == [audience]