Example #1
0
 public async void EnterpriseChannelValidation_Succeeds()
 {
     var appId       = "1234567890";
     var serviceUrl  = "https://webchat.botframework.com/";
     var credentials = new SimpleCredentialProvider(appId, String.Empty);
     var identity    = new SimpleClaimsIdentity(new List <Claim>()
     {
         new Claim(AuthenticationConstants.AudienceClaim, appId, null, AuthenticationConstants.ToBotFromChannelTokenIssuer),
         new Claim(AuthenticationConstants.ServiceUrlClaim, serviceUrl, null),
     }, true);
     await EnterpriseChannelValidation.ValidateIdentity(identity, credentials, serviceUrl);
 }
Example #2
0
        public async void EnterpriseChannelValidation_NoAudienceClaim_Fails()
        {
            var appId       = "1234567890";
            var serviceUrl  = "https://webchat.botframework.com/";
            var credentials = new SimpleCredentialProvider(appId, String.Empty);
            var identity    = new SimpleClaimsIdentity(new List <Claim>()
            {
                new Claim(AuthenticationConstants.ServiceUrlClaim, serviceUrl, null),
            }, true);

            await Assert.ThrowsAsync <UnauthorizedAccessException>(
                async() => await EnterpriseChannelValidation.ValidateIdentity(identity, credentials, serviceUrl));
        }
Example #3
0
        public async void GovernmentChannelValidation_WrongServiceClaimValue_Fails()
        {
            var appId       = "1234567890";
            var serviceUrl  = "https://webchat.botframework.com/";
            var credentials = new SimpleCredentialProvider(appId, String.Empty);
            var identity    = new SimpleClaimsIdentity(new List <Claim>()
            {
                new Claim(AuthenticationConstants.AudienceClaim, appId, null, GovernmentAuthenticationConstants.ToBotFromChannelTokenIssuer),
                new Claim(AuthenticationConstants.ServiceUrlClaim, "other", null),
            }, true);

            await Assert.ThrowsAsync <UnauthorizedAccessException>(
                async() => await GovernmentChannelValidation.ValidateIdentity(identity, credentials, serviceUrl));
        }
        public void ToComplexEntity_WhenSimpleEntity_ExpectCorrectMap()
        {
            // Arrange
            var mockClaimMappers = new Mock<IMapper<SimpleClaim, Claim>>();

            mockClaimMappers.Setup(r => r.ToComplexEntity(It.IsAny<IEnumerable<SimpleClaim>>()))
                .Returns(new List<Claim> { new Claim("val1", "val2") });

            var claimMappers = new ClaimsIdentityMappers(mockClaimMappers.Object);

            var simpleEntity = new SimpleClaimsIdentity
            {
                Claims = new List<SimpleClaim>(),
                AuthenticationType = "AuthenticationType",
                BootstrapContext = "BootstrapContext",
                Label = "Label",
                RoleClaimType = "RoleClaimType",
                NameClaimType = "NameClaimType"
            };

            // Act
            var stopwatch = Stopwatch.StartNew();
            var complexEntity = claimMappers.ToComplexEntity(simpleEntity);
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(complexEntity, Is.Not.Null);

            Assert.That(complexEntity.Claims, Is.Not.Null);
            Assert.That(complexEntity.Claims.Any(), Is.True);
            Assert.That(complexEntity.AuthenticationType, Is.EqualTo("AuthenticationType"));
            Assert.That(complexEntity.BootstrapContext, Is.EqualTo("BootstrapContext"));
            Assert.That(complexEntity.Label, Is.EqualTo("Label"));
            Assert.That(complexEntity.RoleClaimType, Is.EqualTo("RoleClaimType"));
            Assert.That(complexEntity.NameClaimType, Is.EqualTo("NameClaimType"));
        }