public async Task ShouldReturnForbiddenError403_WhenAValidationErrorOccurs()
    {
        AccessDeniedException?exception = null;
        var uri   = "/Fake/Current/Controller1/Action1";
        var input = await setup("Production");

        input.CurrentAction.Action = c =>
        {
            try
            {
                throw new AccessDeniedException(XtiPath.Parse(uri));
            }
            catch (AccessDeniedException ex)
            {
                exception = ex;
                throw;
            }
            return(Task.CompletedTask);
        };
        var response = await input.GetAsync(uri);

        Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Forbidden));
        var result = await response.Content.ReadAsStringAsync();

        var errors         = new[] { new ErrorModel(exception?.DisplayMessage ?? "") };
        var expectedResult = JsonSerializer.Serialize(new ResultContainer <ErrorModel[]>(errors));

        Assert.That(result, Is.EqualTo(expectedResult), "Should return errors");
    }
    public async Task ShouldLogAccessDenied()
    {
        Exception?exception = null;
        var       uri       = "/Fake/Current/Controller1/Action1";
        var       input     = await setup();

        input.CurrentAction.Action = c =>
        {
            try
            {
                throw new AccessDeniedException(XtiPath.Parse(uri));
            }
            catch (Exception ex)
            {
                exception = ex;
                throw;
            }
            return(Task.CompletedTask);
        };
        await input.GetAsync(uri);

        var evt = await getEvent(input);

        Assert.That(evt.Severity, Is.EqualTo(AppEventSeverity.Values.AccessDenied.Value), "Should log access denied");
        Assert.That(evt.Caption, Is.EqualTo("Access Denied"), "Should log access denied");
        Assert.That(evt.Message, Is.EqualTo("Access denied to /Fake/Current/Controller1/Action1"), "Should log access denied");
        Assert.That(evt.Detail, Is.EqualTo(exception?.StackTrace), "Should log access denied");
    }
    public async Task ShouldLogCurrentVersionWithRequest()
    {
        var input = await setup();

        var uri = "/Fake/Current/Controller1/Action1";
        await input.GetAsync(uri);

        var request = await getStartRequest(input);

        var path = XtiPath.Parse(request.Path);

        Assert.That(path.Version, Is.EqualTo(AppVersionKey.Current), "Should log current version");
    }
    public async Task ShouldLogExplicitVersionWithRequest()
    {
        var input = await setup();

        var explicitVersion = await input.AppContext.Version();

        var uri = $"/Fake/{explicitVersion.Key().Value}/Controller1/Action1";
        await input.GetAsync(uri);

        var request = await getStartRequest(input);

        var path = XtiPath.Parse(request.Path);

        Assert.That(path.Version, Is.EqualTo(explicitVersion.Key()), "Should log explicit version");
    }
Ejemplo n.º 5
0
    public XtiPath Value()
    {
        var request = httpContextAccessor.HttpContext?.Request;

        return(XtiPath.Parse($"{request?.PathBase}{request?.Path}"));
    }
Ejemplo n.º 6
0
 public RedirectToAppUserAction(AppFactory factory, XtiPath path, HubAppApi hubApi)
 {
     this.factory = factory;
     this.path    = path;
     this.hubApi  = hubApi;
 }
Ejemplo n.º 7
0
 public AppFromPath(AppFactory factory, XtiPath path)
 {
     this.factory = factory;
     this.path    = path;
 }
Ejemplo n.º 8
0
        public async Task StartRequest(IStartRequestModel startRequest)
        {
            try
            {
                var session = await appFactory.Sessions().Session(startRequest.SessionKey);

                if (session.ID.IsNotValid())
                {
                    session = await startPlaceholderSession(startRequest.SessionKey, new GeneratedKey().Value());
                }
                XtiPath path;
                try
                {
                    path = XtiPath.Parse(startRequest.Path);
                }
                catch
                {
                    path = new XtiPath(AppName.Unknown);
                }
                if (string.IsNullOrWhiteSpace(path.Group))
                {
                    path = path.WithGroup("Home");
                }
                if (string.IsNullOrWhiteSpace(path.Action))
                {
                    path = path.WithAction("Index");
                }
                var appKey = new AppKey(path.App, AppType.Values.Value(startRequest.AppType));
                var app    = await appFactory.Apps().App(appKey);

                var version = await app.Version(path.Version);

                var resourceGroup = await version.ResourceGroup(path.Group);

                var resource = await resourceGroup.Resource(path.Action);

                var modCategory = await resourceGroup.ModCategory();

                var modifier = await modCategory.Modifier(path.Modifier);

                var request = await appFactory.Requests().Request(startRequest.RequestKey);

                if (request.ID.IsValid())
                {
                    await request.Edit
                    (
                        session,
                        resource,
                        modifier,
                        startRequest.Path,
                        startRequest.TimeStarted
                    );
                }
                else
                {
                    await session.LogRequest
                    (
                        startRequest.RequestKey,
                        resource,
                        modifier,
                        startRequest.Path,
                        startRequest.TimeStarted
                    );
                }
            }
            catch (Exception ex)
            {
                await handleError(ex);
            }
        }