예제 #1
0
def test_token_generator(private_key, public_key):
    """Test that the baseline token generator behaves as expected"""
    token = generate_token(
        username="******",
        private_key=private_key,
        lifetime=timedelta(seconds=90),
        claims=["A_CLAIM"],
    )
    decoded = jwt.decode(jwt=token, key=public_key, algorithms=["RS256"])
    assert decoded["identity"] == "test"
    assert decompress_claims(decoded["user_claims"]) == ["A_CLAIM"]
    assert "aud" not in decoded
예제 #2
0
def test_token_generator_with_audience(private_key, public_key):
    """Test that the baseline token generator behaves as expected when given an audience"""
    token = generate_token(
        flowapi_identifier="test_audience",
        username="******",
        private_key=private_key,
        lifetime=timedelta(seconds=90),
        claims=["A_CLAIM"],
    )
    decoded = jwt.decode(
        jwt=token,
        key=public_key,
        algorithms=["RS256"],
        audience="test_audience",
    )
    assert decoded["identity"] == "test"
    assert decompress_claims(decoded["user_claims"]) == ["A_CLAIM"]
예제 #3
0
# Format pandas tables nicely


def to_md(self):
    return tabulate.tabulate(self.head(), self.columns, tablefmt="pipe")


def format_dict(x):
    return f'><div class="codehilite"><pre>{pprint.pformat(x)}</pre></div>'


get_ipython().display_formatter.formatters["text/html"].for_type(
    pd.DataFrame, to_md)
get_ipython().display_formatter.formatters["text/markdown"].for_type(
    dict, format_dict)
get_ipython().display_formatter.formatters["text/markdown"].for_type(
    str, lambda x: f">`{x}`")
get_ipython().display_formatter.formatters["text/markdown"].for_type(
    list, lambda x: f">`{x}`")

# Create an API access token

TOKEN = generate_token(
    username="******",
    private_key=load_private_key(os.environ["PRIVATE_JWT_SIGNING_KEY"]),
    lifetime=timedelta(days=1),
    claims=get_all_claims_from_flowapi(flowapi_url="http://localhost:9090"),
    flowapi_identifier=os.environ["FLOWAPI_IDENTIFIER"],
)