예제 #1
0
        public void WriteSymmetric_ShortSharedKey_ShouldThrowArgumentOutOfRangeException()
        {
            // GIVEN a valid JWTWriter, issuer, audience and an empty sharedKey
            var sut       = new JWTWriter();
            var issuer    = "some-issuer";
            var audience  = "some-audience";
            var sharedKey = "1234";

            // WHEN writing the JWT
            Action act = () => sut.WriteSymmetric(issuer, audience, DateTime.MaxValue, sharedKey, null);

            // THEN it should throw ArgumentOutOfRangeException
            act.Should().Throw <ArgumentOutOfRangeException>();
        }
예제 #2
0
        public void WriteSymmetric_EmptyAudience_ShouldThrowArgumentNullException()
        {
            // GIVEN a valid JWTWriter, sharedKey, issuer and an empty audience
            var sut       = new JWTWriter();
            var issuer    = "some-issuer";
            var audience  = "";
            var sharedKey = "b7vUtYUvmR46ifoddrccuWCHeRMfm2qw";

            // WHEN writing the JWT
            Action act = () => sut.WriteSymmetric(issuer, audience, DateTime.MaxValue, sharedKey, null);

            // THEN it should throw ArgumentNullException
            act.Should().Throw <ArgumentNullException>()
            .And.Message.Should().Contain(nameof(audience));
        }
예제 #3
0
        public void WriteSymmetric_EmptySharedKey_ShouldThrowArgumentNullException()
        {
            // GIVEN a valid JWTWriter, issuer, audience and an empty sharedKey
            var sut       = new JWTWriter();
            var issuer    = "some-issuer";
            var audience  = "some-audience";
            var sharedKey = "";

            // WHEN writing the JWT
            Action act = () => sut.WriteSymmetric(issuer, audience, DateTime.MaxValue, sharedKey, null);

            // THEN it should throw ArgumentNullException
            act.Should().Throw <ArgumentNullException>()
            .And.Message.Should().Contain(nameof(sharedKey));
        }
예제 #4
0
        public void WriteSymmetric_ValidArgs_ShouldReturnAValidJWT()
        {
            // GIVEN a valid JWTWriter, issuer, audience, sharedKey and some claims
            var sut       = new JWTWriter();
            var issuer    = "some-issuer";
            var audience  = "some-audience";
            var sharedKey = "b7vUtYUvmR46ifoddrccuWCHeRMfm2qw";
            var claims    = new Dictionary <string, object>
            {
                { "some-claim-int", 123456 },
                { "some-claim-bool", false },
                { "some-claim-array", new string[] { "item1", "item2" } }
            };

            // WHEN writing the JWT
            var jwt = sut.WriteSymmetric(issuer, audience, DateTime.MaxValue, sharedKey, claims);

            // THEN the JWT is the expected one
            var expected = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lLWNsYWltLWludCI6MTIzNDU2LCJzb21lLWNsYWltLWJvb2wiOmZhbHNlLCJzb21lLWNsYWltLWFycmF5IjpbIml0ZW0xIiwiaXRlbTIiXSwiZXhwIjoyNTM0MDIzMDA4MDAsImlzcyI6InNvbWUtaXNzdWVyIiwiYXVkIjoic29tZS1hdWRpZW5jZSJ9.jGjRCItE2n42ZUu7h4GzH-oT8n1Y5wjzs73NYQUcmJk";

            jwt.Should().Be(expected);
        }