Пример #1
0
    static void Main(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("A single argument should be provided:");
            Console.WriteLine("dotnet decode-jwt eyJhbGciOiJub25lIn0.ewogICAgImlzcyI6ICJiZXN0LWlzc3VlciIsCiAgICAic3ViIjogIm5pY2Utc3ViamVjdCIsCiAgICAiYXVkIjogWyJhdWRpZW5jZS1vbmUiLCAiYXVkaWVuY2UtdHdvIl0sCiAgICAiZXhwIjogMTUyODY5MTM1MCwKICAgICJuYmYiOiAxNTI4NjkwNzUwLAogICAgImlhdCI6IDE1Mjg2OTA3NTAsCiAgICAianRpIjogImMzMTk3ZGNiLWUxMTMtNDc3OC04OTc5LWI5NTZmNjg0MDA3ZiIsCiAgICAiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvZW1haWxhZGRyZXNzIjogImhpQG1lLmNvbSIsCiAgICAic29tZS1udW1iZXIiOiAxMi41NiwKICAgICJuZXN0ZWQtY2xhaW0iOiB7CiAgICAgICAgImhpIjogIkknbSIsCiAgICAgICAgImEiOiAibmVzdGVkIGNsYWltIgogICAgfQp9Cg==.");
            return;
        }

        var console         = new SimplifiedConsole();
        var claimsDisplayer = new ClaimsDisplayer(console, TimeZoneInfo.Local);

        try
        {
            var claims = JwtClaimsDecoder.GetClaims(args[0]);
            claimsDisplayer.DisplayClaims(claims);
        }
        catch (FormatException e)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(e.Message);
        }
        finally
        {
            Console.ResetColor();
        }
    }
Пример #2
0
    public void GivenNoClaim_WhenDisplayClaims_ThenMessage()
    {
        // Arrange
        var claims = new JsonElement();

        // Act
        _target.DisplayClaims(claims);

        // Assert
        var expected = new List <string>
        {
            "SET FOREGROUND COLOR: DarkGray",
            "WRITE: There was no claims in the JWT.",
            "RESET COLOR"
        };

        _console.Actions.Should().BeEquivalentTo(expected);
    }