public async Task GetClientConnectionInfo()
        {
            var hubName             = "TestHub";
            var hubUrl              = "http://localhost";
            var accessKey           = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var connectionString    = $"Endpoint={hubUrl};AccessKey={accessKey};Version=1.0;";
            var userId              = "User";
            var idToken             = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
            var expectedName        = "John Doe";
            var expectedIat         = "1516239022";
            var claimTypeList       = new string[] { "name", "iat" };
            var connectionStringKey = Constants.AzureSignalRConnectionStringName;
            var configDict          = new Dictionary <string, string>()
            {
                { Constants.ServiceTransportTypeName, "Transient" }, { connectionStringKey, connectionString }
            };
            var configuration       = new ConfigurationBuilder().AddInMemoryCollection(configDict).Build();
            var serviceManagerStore = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, SingletonAzureComponentFactory.Instance, new TestRouter());
            var azureSignalRClient  = await SignalRUtils.GetAzureSignalRClientAsync(connectionStringKey, hubName, serviceManagerStore);

            var connectionInfo = await azureSignalRClient.GetClientConnectionInfoAsync(userId, idToken, claimTypeList, null);

            Assert.Equal(connectionInfo.Url, $"{hubUrl}/client/?hub={hubName.ToLower()}");

            var claims = new JwtSecurityTokenHandler().ReadJwtToken(connectionInfo.AccessToken).Claims;

            Assert.Equal(expectedName, GetClaimValue(claims, "name"));
            Assert.Equal(expectedIat, GetClaimValue(claims, $"{AzureSignalRClient.AzureSignalRUserPrefix}iat"));
        }
Beispiel #2
0
        public void GetHubNameTest()
        {
            var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();

            configuration["AzureSignalRConnectionString:serviceUri"] = "https://abc.com";
            using var serviceManagerStore = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, SingletonAzureComponentFactory.Instance, new EndpointRouterDecorator());
            var myHub = new MyHub(serviceManagerStore);

            Assert.Equal("MyHub", myHub.HubName);
        }
        public void GetServiceManager_WithSingleEndpoint()
        {
            var connectionString    = FakeEndpointUtils.GetFakeConnectionString(1).Single();
            var configuration       = new ConfigurationBuilder().AddInMemoryCollection().Build();
            var connectionStringKey = "key";

            configuration[connectionStringKey] = connectionString;

            var managerStore    = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, null);
            var hubContextStore = managerStore.GetOrAddByConnectionStringKey(connectionStringKey);
            var manager         = hubContextStore.ServiceManager;
        }
Beispiel #4
0
        public void TestWithoutSignalRConnectionAttribute()
        {
            var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();

            using var serviceManagerStore = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, SingletonAzureComponentFactory.Instance, new EndpointRouterDecorator());

            Assert.Throws <InvalidOperationException>(() => new MyHub(serviceManagerStore));

            configuration["AzureSignalRConnectionString:serviceUri"] = "https://abc.com";
            var myHub = new MyHub(serviceManagerStore);

            Assert.NotNull(serviceManagerStore.GetByConfigurationKey("AzureSignalRConnectionString"));
        }
Beispiel #5
0
        public void TestCustomSignalRConnectionAttribute()
        {
            var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();

            using var serviceManagerStore = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, SingletonAzureComponentFactory.Instance, Options.Create(new SignalROptions()));

            Assert.Throws <InvalidOperationException>(() => new CustomConnectionHub(serviceManagerStore));

            configuration["SignalRConnection:serviceUri"] = "https://abc.com";
            var myHub = new CustomConnectionHub(serviceManagerStore);

            Assert.NotNull(serviceManagerStore.GetByConfigurationKey("SignalRConnection"));
        }
        public async Task EndpointsEqualFact()
        {
            var configuration       = CreateTestConfiguration();
            var serviceManagerStore = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, SingletonAzureComponentFactory.Instance, Options.Create(new SignalROptions()));
            var converter           = new NegotiationContextAsyncConverter(serviceManagerStore);
            var attribute           = new SignalRNegotiationAttribute {
                HubName = HubName
            };

            var endpointList = (await converter.ConvertAsync(attribute, default)).Endpoints.Select(e => e.Name);

            foreach (var expectedEndpoint in Endpoints)
            {
                Assert.Contains(expectedEndpoint.Name, endpointList);
            }
        }
Beispiel #7
0
        public void GetClientConnectionInfo()
        {
            var hubName             = "TestHub";
            var hubUrl              = "http://localhost";
            var accessKey           = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var connectionString    = $"Endpoint={hubUrl};AccessKey={accessKey};Version=1.0;";
            var userId              = "User";
            var idToken             = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
            var expectedName        = "John Doe";
            var expectedIat         = "1516239022";
            var claimTypeList       = new string[] { "name", "iat" };
            var serviceManagerStore = new ServiceManagerStore(ServiceTransportType.Transient, null, null);
            var azureSignalRClient  = new AzureSignalRClient(serviceManagerStore, connectionString, hubName);
            var connectionInfo      = azureSignalRClient.GetClientConnectionInfo(userId, idToken, claimTypeList);

            Assert.Equal(connectionInfo.Url, $"{hubUrl}/client/?hub={hubName.ToLower()}");

            var claims = new JwtSecurityTokenHandler().ReadJwtToken(connectionInfo.AccessToken).Claims;

            Assert.Equal(expectedName, GetClaimValue(claims, "name"));
            Assert.Equal(expectedIat, GetClaimValue(claims, $"{AzureSignalRClient.AzureSignalRUserPrefix}iat"));
        }
Beispiel #8
0
 /// <summary>
 /// Gets <see cref="IServiceHubContextStore"/>.
 /// If the <see cref="IServiceHubContextStore"/> for a specific connection string exists, returns the <see cref="IServiceHubContextStore"/>,
 /// otherwise creates one and then returns it.
 /// </summary>
 /// <param name="configurationKey"> is the connection string configuration key.</param>
 /// <returns>The returned value is an instance of <see cref="IServiceHubContextStore"/>.</returns>
 public static IServiceHubContextStore Get(string configurationKey = Constants.AzureSignalRConnectionStringName) =>
 ServiceManagerStore.GetOrAddByConfigurationKey(configurationKey);