public void ConstructFromDomain() { Uri expected = new Uri("https://sts.eastus2.mixedreality.com"); Uri actual = AuthenticationEndpoint.ConstructFromDomain("eastus2.mixedreality.com"); Assert.AreEqual(expected, actual); }
public void ConstructFromDomainWithInvalidParameters() { ArgumentException?ex = Assert.Throws <ArgumentNullException>(() => AuthenticationEndpoint.ConstructFromDomain(null !)); Assert.AreEqual("accountDomain", ex !.ParamName); ex = Assert.Throws <ArgumentException>(() => AuthenticationEndpoint.ConstructFromDomain(string.Empty)); Assert.AreEqual("accountDomain", ex !.ParamName); ex = Assert.Throws <ArgumentException>(() => AuthenticationEndpoint.ConstructFromDomain(" ")); Assert.AreEqual("accountDomain", ex !.ParamName); }
public async Task CreateToken_ValidCredentials_ValidTokenReturned() { //arrange var authenticationClient = new AuthenticationEndpoint(_baseConfiguration, _authenticationConfiguration, GetDefaultSezzleHttpClient()); //act var resp = await authenticationClient.CreateTokenAsync(); //assert Assert.AreNotEqual(0, resp.Token.Length); Assert.Greater(resp.ExpirationDate, DateTime.Now); }
public void AuthenticateWith2fa_WithGoodUserId_ReturnsAccessToken() { var apiHelper = CreateApiHelper(GetValidResponse()); var authenticationEndpoint = new AuthenticationEndpoint(apiHelper); var sut = authenticationEndpoint.Authenticate2Fa(_authenticatedUser.UserId).Result; Assert.IsNotNull(sut); Assert.AreEqual(_authenticatedUser.Username, sut.Username); Assert.IsTrue(sut.Authenticated, "Returned user is not authenticated."); Assert.IsNotNull(sut.AccessToken, "Access token was not returned."); }
public void Authenticate_WithBadCredentials_ReturnsNullAccessToken() { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest }; var apiHelper = CreateApiHelper(response); var authenticationEndpoint = new AuthenticationEndpoint(apiHelper); var sut = authenticationEndpoint.Authenticate((UserCredentials)null).Result; Assert.IsNotNull(sut); Assert.IsFalse(sut.Authenticated, "Returned user is authenticated."); Assert.IsNull(sut.AccessToken, "Access token was returned."); Assert.AreEqual("Bad Request", sut.FailedReason); }
public void CreateToken_BadSezzleUrlEndpoint_ExceptionThrown() { Func <Task> act = async() => { //arrange _baseConfiguration.ApiUrl += "aaaaa/"; var authenticationClient = new AuthenticationEndpoint(_baseConfiguration, _authenticationConfiguration, GetDefaultSezzleHttpClient()); //act var resp = await authenticationClient.CreateTokenAsync(); }; //assert act.Should().Throw <SezzleErrorResponseException>(); }
public void CreateToken_InvalidCredentials_BadPrivateKey_TargetedExceptionThrown() { Func <Task> act = async() => { //arrange _authenticationConfiguration.ApiPrivateKey += "bad"; var authenticationClient = new AuthenticationEndpoint(_baseConfiguration, _authenticationConfiguration, GetDefaultSezzleHttpClient()); //act var resp = await authenticationClient.CreateTokenAsync(); }; //assert act.Should().Throw <SezzleErrorResponseException>(); }
public void CreateToken_ValidUrlThatIsNotSezzle_KnownExceptionThrown() { Func <Task> act = async() => { //arrange _baseConfiguration.ApiUrl = "http://www.google.com"; var authenticationClient = new AuthenticationEndpoint(_baseConfiguration, _authenticationConfiguration, GetDefaultSezzleHttpClient()); //act var resp = await authenticationClient.CreateTokenAsync(); }; //assert act.Should().Throw <SezzleErrorResponseException>(); }
public void CreateToken_BlankUrl_ExceptionThrown() { Func <Task> act = async() => { //arrange _baseConfiguration.ApiUrl = string.Empty; var authenticationClient = new AuthenticationEndpoint(_baseConfiguration, _authenticationConfiguration, GetDefaultSezzleHttpClient()); //act var resp = await authenticationClient.CreateTokenAsync(); }; //assert //todo: get these other unit tests working. act.Should().Throw <System.UriFormatException>(); }
public GenerateSuperUser(AuthenticationEndpoint authenticationEndpoint) { this.authenticationEndpoint = authenticationEndpoint; UserModel user = new UserModel() { Username = "******", FirstName = "Admin", LastName = "Admin", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; if (!Exists(user)) { this.authenticationEndpoint.Register(user, "admin"); } }
/// <summary> /// Initializes a new instance of the <see cref="RemoteRenderingClient" /> class. /// </summary> /// <param name="remoteRenderingEndpoint">The rendering service endpoint. This determines the region in which the rendering VM is created.</param> /// <param name="accountId">The Azure Remote Rendering account identifier.</param> /// <param name="accountDomain">The Azure Remote Rendering account domain.</param> /// <param name="credential">The credential used to access the Mixed Reality service.</param> /// <param name="options">The options.</param> public RemoteRenderingClient(Uri remoteRenderingEndpoint, Guid accountId, string accountDomain, TokenCredential credential, RemoteRenderingClientOptions options = null) { Argument.AssertNotDefault(ref accountId, nameof(accountId)); Argument.AssertNotNullOrWhiteSpace(accountDomain, nameof(accountDomain)); Argument.AssertNotNull(credential, nameof(credential)); options ??= new RemoteRenderingClientOptions(); Uri authenticationEndpoint = options.AuthenticationEndpoint ?? AuthenticationEndpoint.ConstructFromDomain(accountDomain); TokenCredential mrTokenCredential = MixedRealityTokenCredential.GetMixedRealityCredential(accountId, authenticationEndpoint, credential); _accountId = accountId; _clientDiagnostics = new ClientDiagnostics(options); _pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(mrTokenCredential, GetDefaultScope(remoteRenderingEndpoint))); _restClient = new RemoteRenderingRestClient(_clientDiagnostics, _pipeline, remoteRenderingEndpoint.ToString(), options.Version); }
/// <summary> /// Initializes a new instance of the <see cref="ObjectAnchorsConversionClient" /> class. /// </summary> /// <param name="accountId">The Azure Object Anchors account ID.</param> /// <param name="accountDomain">The Azure Object Anchors account domain.</param> /// <param name="credential">The credential used to access the Mixed Reality service.</param> /// <param name="options">The options.</param> public ObjectAnchorsConversionClient(Guid accountId, string accountDomain, TokenCredential credential, ObjectAnchorsConversionClientOptions options = null) { Argument.AssertNotDefault(ref accountId, nameof(accountId)); Argument.AssertNotNullOrWhiteSpace(accountDomain, nameof(accountDomain)); Argument.AssertNotNull(credential, nameof(credential)); options = options ?? new ObjectAnchorsConversionClientOptions(); Uri authenticationEndpoint = options.MixedRealityAuthenticationEndpoint ?? AuthenticationEndpoint.ConstructFromDomain(accountDomain); TokenCredential mrTokenCredential = MixedRealityTokenCredential.GetMixedRealityCredential(accountId, authenticationEndpoint, credential, options.MixedRealityAuthenticationOptions); Uri serviceEndpoint = options.ServiceEndpoint ?? ConstructObjectAnchorsEndpointUrl(accountDomain); AccountId = accountId; SupportedAssetFileTypesSet = options.SupportedAssetFileTypes; _clientDiagnostics = new ClientDiagnostics(options); _pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(mrTokenCredential, GetDefaultScope(serviceEndpoint))); _getBlobUploadEndpointRestClient = new BlobUploadEndpointRestClient(_clientDiagnostics, _pipeline, serviceEndpoint, options.Version); _ingestionJobRestClient = new IngestionJobRestClient(_clientDiagnostics, _pipeline, serviceEndpoint, options.Version); }