コード例 #1
0
            public async void GenerateClaimsForIdentity_NoIssuer_ThrowException()
            {
                var expectedInvalidIssuer = TestHelper.GenerateRandomString();
                var issuer = TestHelper.GenerateRandomString();

                authenticateInfo = GenerateAuthenticateInfo(issuer, false);
                authenticateInfo.Properties.Items["scheme"] = FabricIdentityConstants.AuthenticationSchemes.Azure;
                AppConfiguration.AzureActiveDirectorySettings.IssuerWhiteList = new string[]
                {
                    issuer = expectedInvalidIssuer
                };
                Exception expectedException = null;

                try
                {
                    var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest);

                    Assert.True(false, "The code should not call this line.  It should have thrown an exception.");
                }
                catch (Exception exc)
                {
                    expectedException = exc;
                }

                Assert.NotNull(expectedException);
                Assert.IsType <MissingIssuerClaimException>(expectedException);
                Assert.Equal <string>(
                    ExceptionMessageResources.MissingIssuerClaimMessage,
                    expectedException.Message);
            }
コード例 #2
0
            public async void GenerateClaimsForIdentity_HappyPathNonAzure_RemovesNameIdentitiferUserIdClaim()
            {
                authenticateInfo = GenerateAuthenticateInfo(null, true, false);

                var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest);

                Assert.False(result.Claims.Any(x => x.Type == ClaimTypes.NameIdentifier));
            }
コード例 #3
0
            public async void GenerateClaimsForIdentity_HappyPathNonAzure_RemovesSubjectUserIdClaim()
            {
                authenticateInfo = GenerateAuthenticateInfo(null, true, false);

                var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest);

                Assert.DoesNotContain(result.Claims, x => x.Type == JwtClaimTypes.Subject);
            }
コード例 #4
0
            public async void GenerateClaimsForIdentity_HappyPathAzure_ReturnsClaimsResult()
            {
                var issuer = TestHelper.GenerateRandomString();

                authenticateInfo = GenerateAuthenticateInfo(issuer);
                authenticateInfo.Properties.Items["scheme"] = FabricIdentityConstants.AuthenticationSchemes.Azure;
                AppConfiguration.AzureActiveDirectorySettings.IssuerWhiteList = new string[]
                {
                    issuer = "LOCAL AUTHORITY"
                };

                var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest);

                AssertClaimsResult(authenticateInfo, authorizationRequest, result);
            }
コード例 #5
0
            public async void GenerateClaimsForIdentity_NullInfo_ReturnsException()
            {
                Exception excResult = null;

                try
                {
                    var result = await ClaimsService.GenerateClaimsForIdentity(null, new AuthorizationRequest());

                    Assert.True(false, "Should not get past this function call.");
                }
                catch (Exception exc)
                {
                    excResult = exc;
                }

                Assert.NotNull(excResult);
                Assert.IsType <ArgumentNullException>(excResult);
                Assert.True(excResult.Message.Contains("The object name 'info' cannot be null."));
            }
コード例 #6
0
            public async void GenerateClaimsForIdentity_NoUserIdClaim_ThrowException()
            {
                authenticateInfo = GenerateAuthenticateInfo(null, true, false, false);

                Exception expectedException = null;

                try
                {
                    var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest);

                    Assert.True(false, "The code should not call this line.  It should have thrown an exception.");
                }
                catch (Exception exc)
                {
                    expectedException = exc;
                }

                Assert.NotNull(expectedException);
                Assert.IsType <MissingUserClaimException>(expectedException);
                Assert.Equal <string>(
                    ExceptionMessageResources.MissingUserClaimMessage,
                    expectedException.Message);
            }
コード例 #7
0
            public async void GenerateClaimsForIdentity_HappyPathNonAzure_ReturnsClaimsResult()
            {
                var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest);

                AssertClaimsResult(authenticateInfo, authorizationRequest, result);
            }