Ejemplo n.º 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.SuspendTransfer
                 )] GetTransferRequest getTransferRequest,
            IDictionary <string, string> headers
            )
        {
            try
            {
                AccessTokenResult = await accessTokenValidator.ValidateToken(headers);

                switch (AccessTokenResult)
                {
                case ValidAccessTokenResult _:
                    var(transferToken, _, _, _) = getTransferRequest;

                    await transfersService.SuspendTransfer(new GetTransferParameters
                    {
                        TransferToken = transferToken
                    });

                    return(LogOk());

                default:
                    return(LogUnauthorized());
                }
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Looks up an existing transfer.
        /// </summary>
        /// <param name="transferId">the transfer id</param>
        /// <returns>the transfer record</returns>
        public Task <Transfer> GetTransfer(string transferId)
        {
            var request = new GetTransferRequest {
                TransferId = transferId
            };

            return(gateway(authenticationContext()).GetTransferAsync(request)
                   .ToTask(response => response.Transfer));
        }
Ejemplo n.º 3
0
        internal static IEnumerable <TestCaseData> InvalidRequests()
        {
            getTransferRequest = new GetTransferRequest
            {
            };
            accessTokenResult = new Mock <ValidAccessTokenResult>().Object;
            throws            = true;

            yield return(GetTestCaseWhen("Token is valid, body is missing transferToken and client is requesting"));
        }
Ejemplo n.º 4
0
        public async Task Should_Return200_When_ValidRequest(
            GetTransferRequest getTransferRequest,
            IDictionary <string, string> headers,
            IAccessTokenResult accessTokenResult,
            bool throws
            )
        {
            mockAccessTokenValidator.SetupValidateToken(accessTokenResult);
            mockTransfersService.SetupSuspendTransfer(throws);

            var response = await mockFunction.Run(getTransferRequest, headers);

            Assert.That(response, Is.InstanceOf <OkResult>());
        }
Ejemplo n.º 5
0
        internal static IEnumerable <TestCaseData> InvalidRequests()
        {
            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "validToken",
                ContainerUrl  = true
            };
            accessTokenResult = new Mock <ValidAccessTokenResult>().Object;

            yield return(GetTestCaseWhen("Token is valid, body is missing fields and client is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "validToken",
                Fields        = true
            };

            yield return(GetTestCaseWhen("Token is valid, body is missing containerUrl and client is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                Fields = true
            };

            yield return(GetTestCaseWhen("Token is valid, body is missing transferToken and client is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "validToken",
                ContainerUrl  = false,
                Fields        = false
            };

            yield return(GetTestCaseWhen("Token is valid, body is missing files and restore is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "invalidToken",
                ContainerUrl  = true
            };
            accessTokenResult = new Mock <NoAccessTokenResult>().Object;

            yield return(GetTestCaseWhen("Token is public, body is missing fields and client is requesting"));
        }
Ejemplo n.º 6
0
        internal static IEnumerable <TestCaseData> UnauthorizedRequests()
        {
            accessTokenResult = default;

            yield return(GetTestCaseWhen("Token is invalid, body is valid and client is requesting"));

            accessTokenResult = new Mock <ExpiredAccessTokenResult>().Object;

            yield return(GetTestCaseWhen("Token is expired, body is valid and client is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "validToken",
                ContainerUrl  = false,
                Fields        = false,
                Files         = true
            };

            yield return(GetTestCaseWhen("Token is invalid, body is valid and restore is requesting"));
        }
Ejemplo n.º 7
0
        public async Task Should_Return401Or404_When_UnauthorizedRequest(
            GetTransferRequest getTransferRequest,
            IDictionary <string, string> headers,
            IAccessTokenResult accessTokenResult,
            bool throws
            )
        {
            mockAccessTokenValidator.SetupValidateToken(accessTokenResult);

            var response = await mockFunction.Run(getTransferRequest, headers);

            switch (accessTokenResult)
            {
            case ExpiredAccessTokenResult _:
                Assert.That(response, Is.InstanceOf <UnauthorizedResult>());
                break;

            default:
                Assert.That(response, Is.InstanceOf <NotFoundResult>());
                break;
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.GetTransfer
                 )] GetTransferRequest getTransferRequest,
            IDictionary <string, string> headers
            )
        {
            try
            {
                AccessTokenResult = await accessTokenValidator.ValidateToken(headers);

                switch (AccessTokenResult)
                {
                case ValidAccessTokenResult _:
                case NoAccessTokenResult _:
                    var(transferToken, files, fields, containerUrl) = getTransferRequest;

                    var transfer = await transfersService.GetTransfer(new GetTransferParameters
                    {
                        TransferToken     = transferToken,
                        Files             = files,
                        Fields            = fields,
                        ContainerUrl      = containerUrl,
                        AccessTokenResult = AccessTokenResult
                    });

                    return(LogOkObject(transfer));

                default:
                    return(LogUnauthorized());
                }
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }
Ejemplo n.º 9
0
        public async Task Should_Return500Or404_When_InvalidRequest(
            GetTransferRequest getTransferRequest,
            IDictionary <string, string> headers,
            IAccessTokenResult accessTokenResult,
            bool throws
            )
        {
            mockAccessTokenValidator.SetupValidateToken(accessTokenResult);
            mockTransfersService.SetupSuspendTransfer(throws);

            var response = await mockFunction.Run(getTransferRequest, headers);

            switch (accessTokenResult)
            {
            case ValidAccessTokenResult _:
                Assert.That(response, Is.InstanceOf <InternalServerErrorMessageResult>());
                break;

            default:
                Assert.That(response, Is.InstanceOf <NotFoundResult>());
                break;
            }
        }
Ejemplo n.º 10
0
        internal static IEnumerable <TestCaseData> ValidTransfers()
        {
            accessTokenResult = new Mock <ValidAccessTokenResult>().Object;

            yield return(GetTestCaseWhen("Token and body are valid and client is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "validToken",
                Files         = true
            };

            yield return(GetTestCaseWhen("Token and body are valid and restore is requesting"));

            getTransferRequest = new GetTransferRequest
            {
                TransferToken = "invalidToken",
                ContainerUrl  = true,
                Fields        = true
            };
            accessTokenResult = new Mock <NoAccessTokenResult>().Object;

            yield return(GetTestCaseWhen("Token is public, body is valid and client is requesting"));
        }