Ejemplo n.º 1
0
        public async Task ShouldReturnSingleSecretInfoWhenGetSecretCalled()
        {
            //Given
            const string secretName = "api";
            var          spec       = new SecretSpec {
                Name = secretName
            };

            _swarmClient.GetSecrets().Returns(x => {
                return(Task.FromResult <IEnumerable <Secret> >(new [] { _any.Create <Secret>(),
                                                                        _any.Build <Secret>().With(t => t.Spec, spec).Create() }));
            });
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.GetSecret(secretName);

            var jsonResult = response as JsonResult;
            var value      = jsonResult?.Value as Secret;

            //Then
            Assert.NotNull(jsonResult);
            Assert.NotNull(value);
            Assert.Equal(200, jsonResult.StatusCode);
        }
Ejemplo n.º 2
0
        public SecretTest()
        {
            config = new Mock <IConfiguration>();
            config.SetupGet(x => x[Mikv.Constants.KeyVaultSecretName]).Returns(AssertValues.SecretResult);

            c = new SecretController(logger.Object, config.Object);
        }
Ejemplo n.º 3
0
    void Awake()
    {
        doorSound     = GetComponentInChildren <DoorSound>();
        doorAnim      = GetComponentInChildren <Animator>();
        doorTransform = transform.transform;
        fStep         = transform.Find("FStep").transform;
        bStep         = transform.Find("BStep").transform;

        if (HasComponent <Locked>())
        {
            state  = DoorState.Locked;
            locked = GetComponent <Locked>();
        }
        else if (HasComponent <SecretController>())
        {
            state            = DoorState.Secret;
            secretController = GetComponent <SecretController>();
        }
        else if (HasComponent <DirLockController>())
        {
            state             = DoorState.DirLock;
            dirLockController = GetComponent <DirLockController>();
        }
        else
        {
            state = DoorState.Open;
        }
    }
        public SecretTest()
        {
            // Mock the secret
            config.SetupGet(x => x[Mikv.Constants.KeyVaultSecretName]).Returns(AssertValues.SecretResult);

            // create the controller
            c = new SecretController(logger.Object, config.Object);
        }
Ejemplo n.º 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            SecretController secretController = new SecretController(new SecretBox(), new UploadController(new UploadSecretView(), new SecretService()));

            secretController.secretView.ShowDialog();
        }
Ejemplo n.º 6
0
        public void SecretController_Get()
        {
            SecretController _controller = new SecretController();

            var result = _controller.Get("ignore", "ignore");

            Assert.IsNotNull(result);
        }
        public void Secret2_Get_ReturnsTheLiteralSecret()
        {
            // Arrange
            var controller = new SecretController();

            // Act
            var result = controller.Secret2() as ContentResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.That(result.Content, Is.EqualTo("Top secret 2"));
        }
        public void Gossip_Get_ReturnsRandomText()
        {
            // Arrange
            var controller = new SecretController();

            // Act
            var result = controller.Gossip() as ContentResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.That(result.Content, Is.Not.Empty);
        }
        public void Gossip_Get_ReturnsDifferentTextEachTime()
        {
            // Arrange
            var controller = new SecretController();

            // Act
            ContentResult result1 = controller.Secret1() as ContentResult;
            ContentResult result2 = controller.Secret2() as ContentResult;

            // Assert
            Assert.IsNotNull(result1);
            Assert.IsNotNull(result2);
            Assert.That(result1.Content, Is.Not.EqualTo(result2.Content));
        }
Ejemplo n.º 10
0
        public async Task ShouldReturnBadRequestWhenDeleteSecretCalledWithEmptyId()
        {
            //Given
            _swarmClient.DeleteSecret(Arg.Any <string>()).Returns(x => Task.CompletedTask);
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.DeleteSecret(string.Empty);

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(400, result.StatusCode);
        }
Ejemplo n.º 11
0
        public async Task ShouldDeleteSecretWhenDeleteSecretCalled()
        {
            //Given
            _swarmClient.DeleteSecret(Arg.Any <string>()).Returns(x => Task.CompletedTask);
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.DeleteSecret(_any.Create <string>());

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(204, result.StatusCode);
            await _swarmClient.Received(1).DeleteSecret(Arg.Any <string>());
        }
Ejemplo n.º 12
0
        public async Task ShouldReturnInternalServerErrorWhenGetSecretsCalledAndErrorOccour()
        {
            //Given
            _swarmClient.When(x => {
                x.GetSecrets();
            }).Do(_ => { throw new Exception(); });
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.GetSecret("");

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(500, result.StatusCode);
        }
Ejemplo n.º 13
0
        public async Task ShouldReturnBadRequestWhenNameIsEmpty()
        {
            //Given
            _swarmClient.CreateSecret(Arg.Any <SecretSpec>()).Returns(x => _any.Create <SecretCreateResponse>());
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.CreateSecret(new SwarmApi.Dtos.SecretParameters {
                Content = _any.Create <string>(),
                Name    = string.Empty
            });

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(400, result.StatusCode);
            Assert.Equal("Name field cannot be empty.", result.Content);
        }
Ejemplo n.º 14
0
        public async Task ShouldCreateNewSecretWhenCreateSecretCalled()
        {
            //Given
            const string secretName = "test-secret";

            _swarmClient.CreateSecret(Arg.Any <SecretSpec>()).Returns(x => _any.Create <SecretCreateResponse>());
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.CreateSecret(new SwarmApi.Dtos.SecretParameters {
                Content = _any.Create <string>(),
                Name    = secretName
            });

            var result = response as CreatedResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal($"/api/secret/{secretName}", result.Location);
        }
Ejemplo n.º 15
0
        public async Task ShouldReturnAllSecretInfoWhenGetSecretsCalled()
        {
            //Given
            _swarmClient.GetSecrets().Returns(x => {
                return(Task.FromResult <IEnumerable <Secret> >(new [] { _any.Create <Secret>(), _any.Create <Secret>() }));
            });
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.GetSecrets();

            var jsonResult = response as JsonResult;
            var value      = jsonResult?.Value as IEnumerable <Secret>;

            //Then
            Assert.NotNull(jsonResult);
            Assert.NotNull(value);
            Assert.Equal(200, jsonResult.StatusCode);
            Assert.Equal(2, value.Count());
        }
Ejemplo n.º 16
0
        public async Task ShouldReturnNotFoundWhenGetSecretCalledDoesNotMatchPredicate()
        {
            //Given
            const string secretName = "api";
            var          spec       = new SecretSpec {
                Name = secretName
            };

            _swarmClient.GetSecrets().Returns(x => {
                return(Task.FromResult <IEnumerable <Secret> >(new [] { _any.Create <Secret>(),
                                                                        _any.Build <Secret>().With(t => t.Spec, spec).Create() }));
            });
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.GetSecret("user-service");

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(404, result.StatusCode);
        }
        public void Generates_Key(int length)
        {
            var result = SecretController.GenerateKey(length);

            Assert.Equal(length, result.Length);
        }
 public void Throws_for_invalid_length(int length)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => SecretController.GenerateKey(length));
 }
 public PlainTextSecret(int length = 48)
 {
     PlainText = SecretController.GenerateKey(length);
 }
Ejemplo n.º 20
0
 public void SetController(SecretController secretController)
 {
     this.secretController = secretController;
 }