public async Task GetRecommendationsWithEncryptedCredentials() { var projectPath = _testAppManager.GetProjectPath(Path.Combine("testapps", "WebAppNoDockerFile", "WebAppNoDockerFile.csproj")); var portNumber = 4000; var aes = Aes.Create(); aes.GenerateKey(); aes.GenerateIV(); using var httpClient = ServerModeHttpClientFactory.ConstructHttpClient(ResolveCredentials, aes); InMemoryInteractiveService interactiveService = new InMemoryInteractiveService(); var keyInfo = new EncryptionKeyInfo { Version = EncryptionKeyInfo.VERSION_1_0, Key = Convert.ToBase64String(aes.Key), IV = Convert.ToBase64String(aes.IV) }; var keyInfoStdin = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(keyInfo))); await interactiveService.StdInWriter.WriteAsync(keyInfoStdin); await interactiveService.StdInWriter.FlushAsync(); var serverCommand = new ServerModeCommand(interactiveService, portNumber, null, false); var cancelSource = new CancellationTokenSource(); var serverTask = serverCommand.ExecuteAsync(cancelSource.Token); try { var restClient = new RestAPIClient($"http://localhost:{portNumber}/", httpClient); await WaitTillServerModeReady(restClient); var startSessionOutput = await restClient.StartDeploymentSessionAsync(new StartDeploymentSessionInput { AwsRegion = _awsRegion, ProjectPath = projectPath }); var sessionId = startSessionOutput.SessionId; Assert.NotNull(sessionId); var getRecommendationOutput = await restClient.GetRecommendationsAsync(sessionId); Assert.NotEmpty(getRecommendationOutput.Recommendations); Assert.Equal("AspNetAppElasticBeanstalkLinux", getRecommendationOutput.Recommendations.FirstOrDefault().RecipeId); var listDeployStdOut = interactiveService.StdOutReader.ReadAllLines(); Assert.Contains("Waiting on symmetric key from stdin", listDeployStdOut); Assert.Contains("Encryption provider enabled", listDeployStdOut); } finally { cancelSource.Cancel(); } }
public async Task AuthEncryptionWithInvalidVersion() { InMemoryInteractiveService interactiveService = new InMemoryInteractiveService(); var portNumber = 4010; var aes = Aes.Create(); aes.GenerateKey(); aes.GenerateIV(); var keyInfo = new EncryptionKeyInfo { Version = "not-valid", Key = Convert.ToBase64String(aes.Key), IV = Convert.ToBase64String(aes.IV) }; var keyInfoStdin = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(keyInfo))); await interactiveService.StdInWriter.WriteAsync(keyInfoStdin); await interactiveService.StdInWriter.FlushAsync(); var serverCommand = new ServerModeCommand(interactiveService, portNumber, null, false); var cancelSource = new CancellationTokenSource(); Exception actualException = null; try { await serverCommand.ExecuteAsync(cancelSource.Token); } catch (InvalidEncryptionKeyInfoException e) { actualException = e; } finally { cancelSource.Cancel(); } Assert.NotNull(actualException); Assert.Equal("Unsupported symmetric key not-valid", actualException.Message); }
public async Task TcpPortIsInUseTest() { var serverModeCommand1 = new ServerModeCommand(new TestToolInteractiveServiceImpl(), 1234, null, true); var serverModeCommand2 = new ServerModeCommand(new TestToolInteractiveServiceImpl(), 1234, null, true); var serverModeTask1 = serverModeCommand1.ExecuteAsync(); var serverModeTask2 = serverModeCommand2.ExecuteAsync(); await Task.WhenAny(serverModeTask1, serverModeTask2); Assert.False(serverModeTask1.IsCompleted); Assert.True(serverModeTask2.IsCompleted); Assert.True(serverModeTask2.IsFaulted); Assert.NotNull(serverModeTask2.Exception); Assert.Single(serverModeTask2.Exception.InnerExceptions); Assert.IsType <TcpPortInUseException>(serverModeTask2.Exception.InnerException); }
static async Task Main(string[] args) { // Start up the server mode to make the swagger.json file available. var portNumber = 5678; var serverCommand = new ServerModeCommand(new ConsoleInteractiveServiceImpl(), portNumber, null, true); var cancelSource = new CancellationTokenSource(); _ = serverCommand.ExecuteAsync(cancelSource.Token); try { // Wait till server mode is started. await Task.Delay(3000); // Grab the swagger.json from the running instances of server mode var document = await OpenApiDocument.FromUrlAsync($"http://localhost:{portNumber}/swagger/v1/swagger.json"); var settings = new CSharpClientGeneratorSettings { ClassName = "RestAPIClient", GenerateClientInterfaces = true, CSharpGeneratorSettings = { Namespace = "AWS.Deploy.ServerMode.Client", }, HttpClientType = "ServerModeHttpClient" }; var generator = new CSharpClientGenerator(document, settings); var code = generator.GenerateFile(); // Save the generated client to the AWS.Deploy.ServerMode.Client project var fullPath = DetermineFullFilePath("RestAPI.cs"); File.WriteAllText(fullPath, code); } finally { // terminate running server mode. cancelSource.Cancel(); } }
public async Task GetRecommendations() { var projectPath = _testAppManager.GetProjectPath(Path.Combine("testapps", "WebAppNoDockerFile", "WebAppNoDockerFile.csproj")); var portNumber = 4000; using var httpClient = ServerModeHttpClientFactory.ConstructHttpClient(ResolveCredentials); var serverCommand = new ServerModeCommand(_serviceProvider.GetRequiredService <IToolInteractiveService>(), portNumber, null, true); var cancelSource = new CancellationTokenSource(); var serverTask = serverCommand.ExecuteAsync(cancelSource.Token); try { var restClient = new RestAPIClient($"http://localhost:{portNumber}/", httpClient); await WaitTillServerModeReady(restClient); var startSessionOutput = await restClient.StartDeploymentSessionAsync(new StartDeploymentSessionInput { AwsRegion = _awsRegion, ProjectPath = projectPath }); var sessionId = startSessionOutput.SessionId; Assert.NotNull(sessionId); var getRecommendationOutput = await restClient.GetRecommendationsAsync(sessionId); Assert.NotEmpty(getRecommendationOutput.Recommendations); Assert.Equal("AspNetAppElasticBeanstalkLinux", getRecommendationOutput.Recommendations.FirstOrDefault().RecipeId); } finally { cancelSource.Cancel(); } }
public async Task WebFargateDeploymentNoConfigChanges() { _stackName = $"ServerModeWebFargate{Guid.NewGuid().ToString().Split('-').Last()}"; var projectPath = _testAppManager.GetProjectPath(Path.Combine("testapps", "WebAppWithDockerFile", "WebAppWithDockerFile.csproj")); var portNumber = 4001; using var httpClient = ServerModeHttpClientFactory.ConstructHttpClient(ResolveCredentials); var serverCommand = new ServerModeCommand(_serviceProvider.GetRequiredService <IToolInteractiveService>(), portNumber, null, true); var cancelSource = new CancellationTokenSource(); var serverTask = serverCommand.ExecuteAsync(cancelSource.Token); try { var baseUrl = $"http://localhost:{portNumber}/"; var restClient = new RestAPIClient(baseUrl, httpClient); await WaitTillServerModeReady(restClient); var startSessionOutput = await restClient.StartDeploymentSessionAsync(new StartDeploymentSessionInput { AwsRegion = _awsRegion, ProjectPath = projectPath }); var sessionId = startSessionOutput.SessionId; Assert.NotNull(sessionId); var signalRClient = new DeploymentCommunicationClient(baseUrl); await signalRClient.JoinSession(sessionId); var logOutput = new StringBuilder(); signalRClient.ReceiveLogAllLogAction = (line) => { logOutput.AppendLine(line); }; var getRecommendationOutput = await restClient.GetRecommendationsAsync(sessionId); Assert.NotEmpty(getRecommendationOutput.Recommendations); var fargateRecommendation = getRecommendationOutput.Recommendations.FirstOrDefault(x => string.Equals(x.RecipeId, "AspNetAppEcsFargate")); Assert.NotNull(fargateRecommendation); await restClient.SetDeploymentTargetAsync(sessionId, new SetDeploymentTargetInput { NewDeploymentName = _stackName, NewDeploymentRecipeId = fargateRecommendation.RecipeId }); await restClient.StartDeploymentAsync(sessionId); await WaitForDeployment(restClient, sessionId); var stackStatus = await _cloudFormationHelper.GetStackStatus(_stackName); Assert.Equal(StackStatus.CREATE_COMPLETE, stackStatus); Assert.True(logOutput.Length > 0); Assert.Contains("Initiating deployment", logOutput.ToString()); } finally { cancelSource.Cancel(); await _cloudFormationHelper.DeleteStack(_stackName); _stackName = null; } }