public async Task GetLoginForDemo_NoUserAuthenticated_ReturnsLoginCodeForRepositoryWriteUser()
        {
            //Arrange
            var readUser  = new AmazonUser();
            var writeUser = new AmazonUser();

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Is <EnsureRepositoryWithNameCommand>(args => args.Name == "demo"))
            .Returns(new RepositoryResponse(
                         "some-repository-name",
                         "some-repository-url",
                         readUser,
                         writeUser));

            fakeMediator
            .Send(Arg.Is <GetRepositoryLoginForUserQuery>(args => args.AmazonUser == writeUser))
            .Returns(new RepositoryLoginResponse(
                         "some-username",
                         "some-password"));

            var controller = new RegistryController(fakeMediator);

            //Act
            var loginResponse = await controller.GetLoginForDemo();

            var loginObject = loginResponse.ToObject <LoginResponse>();

            //Assert
            Assert.AreEqual("some-repository-url", loginObject.Url);
            Assert.AreEqual("some-username", loginObject.Username);
            Assert.AreEqual("some-password", loginObject.Password);
        }
 private async Task EnsureAuthTokenPolicyForUserAsync(AmazonUser user)
 {
     await EnsurePolicyWithPermissionsForResource(
         user.Name,
         "ecr-login",
         $"*",
         new[]
     {
         "ecr:GetAuthorizationToken"
     });
 }
 public RepositoryResponse(
     string name,
     string hostName,
     AmazonUser readUser,
     AmazonUser writeUser)
 {
     this.Name      = name;
     this.HostName  = hostName;
     this.ReadUser  = readUser;
     this.WriteUser = writeUser;
 }
Exemple #4
0
        public async Task Deploy_UserIdGiven_DeployToClusterCommandFiredWithAuthorizationFromRepository()
        {
            //Arrange
            var readUser  = new AmazonUser();
            var writeUser = new AmazonUser();

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            fakeMediator
            .Send(Arg.Is <GetRepositoryLoginForUserQuery>(arg =>
                                                          arg.AmazonUser == readUser))
            .Returns(new RepositoryLoginResponse(
                         "some-username",
                         "some-password"));

            fakeMediator
            .Send(Arg.Is <EnsureRepositoryWithNameCommand>(arg => arg.UserId != null))
            .Returns(new RepositoryResponse(
                         "dummy",
                         "some-host-name",
                         readUser,
                         writeUser));

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new ClustersController(
                fakeMediator,
                fakeMapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Deploy(new DeployToClusterRequest()
            {
                DockerComposeYmlFilePaths = new[] { "some-docker-compose-contents" }
            });

            //Assert
            Assert.IsNotNull(result);

            await fakeMediator
            .Received(1)
            .Send(Arg.Is <DeployToClusterCommand>(args =>
                                                  args.Authentication.Single().Username == "some-username" &&
                                                  args.Authentication.Single().Password == "some-password" &&
                                                  args.Authentication.Single().RegistryHostName == "some-host-name"));
        }
 public GetRepositoryLoginForUserQuery(AmazonUser amazonUser)
 {
     this.AmazonUser = amazonUser;
 }