Exemplo n.º 1
0
 def example(
     self, info, **kwargs
 ) -> typing.List[typing.Union[Edge[int], Edge[str]]]:
     return [
         Edge(cursor=strawberry.ID("1"), node=1),
         Edge(cursor=strawberry.ID("2"), node="string"),
     ]
Exemplo n.º 2
0
    async def parse_id_token(self, token: str) -> User:
        """Verify that the id token generated is correct and return the payload."""
        issuer = f"https://{self.settings.domain}/".format(
            self.settings.domain)
        tv = TokenVerifier(
            signature_verifier=self.signature_verifier,
            issuer=issuer,
            audience=self.settings.client_id,
        )
        await asyncio.to_thread(tv.verify, token)
        payload = jwt.decode(token, verify=False)

        return User(id=strawberry.ID(str(payload["sub"])),
                    name=payload["name"])
Exemplo n.º 3
0
 def person_edge(self) -> Edge[Person]:
     return Edge(cursor=strawberry.ID("1"), node=Person(name="Example"))
Exemplo n.º 4
0
 def person_edge(self) -> EdgeWithCursor[SpecialPerson]:
     return EdgeWithCursor(cursor=strawberry.ID("1"),
                           node=SpecialPerson(name="Example"))
Exemplo n.º 5
0
 def example(self) -> typing.Union[Fallback, Edge[int]]:
     return Edge(cursor=strawberry.ID("1"), node=1)
Exemplo n.º 6
0
 def int_edge(self) -> Edge[int]:
     return Edge(cursor=strawberry.ID("1"), node_field=1)
Exemplo n.º 7
0
    authenticator.send_login_code.side_effect = Exception()

    result = await send_login_code(email, info)
    assert isinstance(result, AuthError)
    assert result.reason == AuthErrorReason.INTERNAL_ERROR


@pytest.mark.parametrize(
    "result",
    [
        Result(error=AuthError.internal_error("Something happened")),
        Result(error=AuthError.temporary_failure("Something happened")),
        Result(error=AuthError.invalid_request("Something happened")),
        Result(error=AuthError.invalid_token("Something happened")),
        Result(value=Authentication(
            user=User(id=strawberry.ID("foo"), name="Someone's Name"),
            access_token="foo",
            refresh_token="bar",
            expires_in=0,
        )),
    ],
)
@pytest.mark.asyncio
async def test_login_with_code_calls_authenticator(
        info: Info, authenticator: MockAuthenticator, result: Result):
    """Check that send_login_code resolver uses authenticator and passes the result through."""
    authenticator.login_with_code.return_value = result

    assert (await login_with_code("InR5cCI6", "*****@*****.**",
                                  info)) == result.collapse()
Exemplo n.º 8
0
 def int_edge(self, info, **kwargs) -> Edge:
     return Edge(cursor=strawberry.ID("1"), node=1)
Exemplo n.º 9
0
            }
        }
        """,
        variables={"email": email},
    )
    assert result.get("errors") is None
    assert result["data"] == {"sendLoginCode": {"emailAddress": email}}


@pytest.mark.parametrize(
    "authentication",
    [
        Authentication(
            access_token="foo",
            refresh_token="bar",
            user=User(id=strawberry.ID("id-1"), name="Foo Name"),
            expires_in=1000,
        )
    ],
)
@pytest.mark.parametrize("code", ["e78bc7a"])
@pytest.mark.parametrize("email", ["*****@*****.**"])
def test_login_with_code(
    client: GraphQLClient,
    email: str,
    code: str,
    authentication: Authentication,
    mocker: MockerFixture,
):
    """
    Check that loginWithCode() endpoint returns Authentication from