public async Task <IActionResult> RegisterRequest(RegistrationRequestMessageViewModel model) { if (ModelState.IsValid) { var address = this.mapper.Map <AddressViewModel, Address>(model.Address); var message = RegistrationRequestMessage.Create(model.FirstName, model.LastName, model.PrivatePhone, address); this.companyWorkData.RegistrationRequestMessages.Add(message); await this.companyWorkData.CompleteAsync(); return(RedirectToAction(nameof(AccountController.Login), "Account")); } return(View(model)); }
public async Task <IActionResult> CreateAcount([FromBody] RegistrationRequestViewModel model) { RegistrationInteractor registrationRequestInteractor = new RegistrationInteractor(_accountRepository); var requestMessage = new RegistrationRequestMessage(model.Email, model.Password, model.FirstName, model.LastName); var responseMessage = await registrationRequestInteractor.Handle(requestMessage); var presenter = new RegistrationResponsePresenter(); var viewModel = presenter.Handle(responseMessage); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(new OkObjectResult(viewModel)); }
public void InvalidCredentialRequests() { var numberOfCredentials = 3; using var rnd = new SecureRandom(); var sk = new CredentialIssuerSecretKey(rnd); var issuer = new CredentialIssuer(sk, numberOfCredentials, rnd); { var client = new WabiSabiClient(sk.ComputeCredentialIssuerParameters(), numberOfCredentials, rnd); // Null request. This requests `numberOfCredentials` zero-value credentials. var(credentialRequest, validationData) = client.CreateRequestForZeroAmount(); var credentialResponse = issuer.HandleRequest(credentialRequest); client.HandleResponse(credentialResponse, validationData); var(validCredentialRequest, _) = client.CreateRequest(Array.Empty <Money>(), client.Credentials.ZeroValue.Take(1)); // Test incorrect number of presentations (one instead of 3.) var presented = validCredentialRequest.Presented.ToArray(); var invalidCredentialRequest = new RegistrationRequestMessage( validCredentialRequest.DeltaAmount, new[] { presented[0] }, // Should present 3 credentials. validCredentialRequest.Requested, validCredentialRequest.Proofs); var ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(invalidCredentialRequest)); Assert.Equal(WabiSabiErrorCode.InvalidNumberOfPresentedCredentials, ex.ErrorCode); Assert.Equal("3 credential presentations were expected but 1 were received.", ex.Message); // Test incorrect number of presentations (0 instead of 3.) presented = credentialRequest.Presented.ToArray(); invalidCredentialRequest = new RegistrationRequestMessage( Money.Coins(2), Array.Empty <CredentialPresentation>(), // Should present 3 credentials. validCredentialRequest.Requested, validCredentialRequest.Proofs); ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(invalidCredentialRequest)); Assert.Equal(WabiSabiErrorCode.InvalidNumberOfPresentedCredentials, ex.ErrorCode); Assert.Equal("3 credential presentations were expected but 0 were received.", ex.Message); (validCredentialRequest, _) = client.CreateRequest(Array.Empty <Money>(), client.Credentials.All); // Test incorrect number of credential requests. invalidCredentialRequest = new RegistrationRequestMessage( validCredentialRequest.DeltaAmount, validCredentialRequest.Presented, validCredentialRequest.Requested.Take(1), validCredentialRequest.Proofs); ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(invalidCredentialRequest)); Assert.Equal(WabiSabiErrorCode.InvalidNumberOfRequestedCredentials, ex.ErrorCode); Assert.Equal("3 credential requests were expected but 1 were received.", ex.Message); // Test incorrect number of credential requests. invalidCredentialRequest = new RegistrationRequestMessage( Money.Coins(2), Array.Empty <CredentialPresentation>(), validCredentialRequest.Requested.Take(1), validCredentialRequest.Proofs); ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(invalidCredentialRequest)); Assert.Equal(WabiSabiErrorCode.InvalidNumberOfRequestedCredentials, ex.ErrorCode); Assert.Equal("3 credential requests were expected but 1 were received.", ex.Message); // Test invalid range proof. var requested = validCredentialRequest.Requested.ToArray(); invalidCredentialRequest = new RegistrationRequestMessage( validCredentialRequest.DeltaAmount, validCredentialRequest.Presented, new[] { requested[0], requested[1], new IssuanceRequest(requested[2].Ma, new[] { GroupElement.Infinity }) }, validCredentialRequest.Proofs); ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(invalidCredentialRequest)); Assert.Equal(WabiSabiErrorCode.InvalidBitCommitment, ex.ErrorCode); } { var client = new WabiSabiClient(sk.ComputeCredentialIssuerParameters(), numberOfCredentials, rnd); var(validCredentialRequest, validationData) = client.CreateRequestForZeroAmount(); // Test invalid proofs. var proofs = validCredentialRequest.Proofs.ToArray(); proofs[0] = proofs[1]; var invalidCredentialRequest = new RegistrationRequestMessage( validCredentialRequest.DeltaAmount, validCredentialRequest.Presented, validCredentialRequest.Requested, proofs); var ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(invalidCredentialRequest)); Assert.Equal(WabiSabiErrorCode.CoordinatorReceivedInvalidProofs, ex.ErrorCode); } { var client = new WabiSabiClient(sk.ComputeCredentialIssuerParameters(), numberOfCredentials, rnd); var(validCredentialRequest, validationData) = client.CreateRequestForZeroAmount(); var credentialResponse = issuer.HandleRequest(validCredentialRequest); client.HandleResponse(credentialResponse, validationData); (validCredentialRequest, validationData) = client.CreateRequest(Enumerable.Empty <Money>(), client.Credentials.All); issuer.HandleRequest(validCredentialRequest); var ex = Assert.Throws <WabiSabiException>(() => issuer.HandleRequest(validCredentialRequest)); Assert.Equal(WabiSabiErrorCode.SerialNumberAlreadyUsed, ex.ErrorCode); } }
public async Task ProcessRequestAsync(RegistrationRequestMessage request) { if (string.IsNullOrWhiteSpace(request.ComponentId)) { throw new ArgumentException( "Argument must be valid component name" , nameof(request.ComponentId)); } if (string.IsNullOrWhiteSpace(request.ComponentType)) { throw new ArgumentException("Component type must not be empty" , nameof(request.ComponentType)); } else if (request.ComponentType != _componentIdentifiers.AnalyserComponentTypeName && request.ComponentType != _componentIdentifiers.DataAcquirerComponentTypeName) { throw new ArgumentOutOfRangeException( nameof(request.ComponentType), "Component type must be valid component identifier"); } if (string.IsNullOrWhiteSpace(request.UpdateChannelName)) { throw new ArgumentException("Argument must be valid channel name" , nameof(request.UpdateChannelName)); } if (string.IsNullOrWhiteSpace(request.InputChannelName)) { throw new ArgumentException("Argument must be valid channel name" , nameof(request.InputChannelName)); } var channelModel = MessageBrokerChannelModel.FromRequest(request); ValidateAttributes(request.ComponentType, request.Attributes); var componentRegisterModel = new ComponentModel( request.ComponentId, request.ComponentType, request.InputChannelName, request.UpdateChannelName, request.Attributes); try { var subscribeComponentModel = await _subscribedComponentManager .SubscribeComponentAsync(componentRegisterModel); } catch (InvalidOperationException) { throw; } catch (Exception e) { _logger.LogError("Unexpected error while processing request: {errorMessage}", e.Message); throw; } await _messageBrokerApi.CreateChannel(channelModel); while (true) { try { await ReplayComponentsJobConfigs(channelModel); break; } catch (HttpRequestException hre) when(hre.Message.Contains("Connection refused")) { _logger.LogError("Could not contact storage. Will try again"); await Task.Delay(TimeSpan.FromSeconds(30)); } catch (Exception e) { _logger.LogError("Could not perform replay - exception: {exception}", e); throw new InvalidOperationException("could not replay components job config", e); } } }