Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Critical] URLRouter miss endpoints #2561

Closed
deviator opened this issue May 18, 2021 · 1 comment · Fixed by #2565
Closed

[Critical] URLRouter miss endpoints #2561

deviator opened this issue May 18, 2021 · 1 comment · Fixed by #2565

Comments

@deviator
Copy link
Contributor

Minimised prepared for testing code

source/app.d

import std;

const data = q{
    PUT /public/devices/commandList
    PUT /public/devices/logicStateList
    OPTIONS /public/devices/commandList
    OPTIONS /public/devices/logicStateList
    PUT /public/mnemoschema
    PUT /public/static
    PUT /public/dynamic
    PUT /public/info
    PUT /public/info-network
    PUT /public/events
    PUT /public/eventList
    PUT /public/availBatteryModels
    OPTIONS /public/availBatteryModels
    OPTIONS /public/dynamic
    OPTIONS /public/eventList
    OPTIONS /public/events
    OPTIONS /public/info
    OPTIONS /public/info-network
    OPTIONS /public/mnemoschema
    OPTIONS /public/static
    PUT /settings/admin/getinfo
    PUT /settings/admin/setconf
    PUT /settings/admin/checksetaccess
    OPTIONS /settings/admin/checksetaccess
    OPTIONS /settings/admin/getinfo
    OPTIONS /settings/admin/setconf
}.splitLines.map!(a=>a.strip.split).filter!(a=>a.length).array;

const ushort port = 8888;

version (check)
{
    void main()
    {
        foreach (a; data)
        {
            const res = executeShell("curl -X %s http://localhost:%d%s".format(a[0], port, a[1]));
            if (res.output.canFind("Not Found")) stderr.writefln!"Not Found %s %s"(a[0], a[1]);
        }
    }
}
else
{
    import vibe.vibe;

    void main()
    {
        auto router = new URLRouter;

        foreach (a; data)
            router.match(a[0].to!HTTPMethod, a[1], (q,s){ s.writeBody("ok"); });

        foreach (r; router.getAllRoutes())
            stderr.writefln!"%s %s"(r.method, r.pattern);

        auto settings = new HTTPServerSettings;
        settings.port = port;
        settings.bindAddresses = ["::", "0.0.0.0"];
        listenHTTP(settings, router);

        runApplication();
    }
}

dub.sdl

name "viberoutebug"

dependency "vibe-d" version="0.9.3"
dependency "vibe-d:tls" version="0.9.3"
subConfiguration "vibe-d:tls" "notls"

(notls only for building on fedora)

server output:

$ dub
Performing "debug" build using /opt/ldc2/bin/ldc2 for x86_64.
...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running viberoutebug 
PUT /public/devices/commandList
PUT /public/devices/logicStateList
OPTIONS /public/devices/commandList
OPTIONS /public/devices/logicStateList
PUT /public/mnemoschema
PUT /public/static
PUT /public/dynamic
PUT /public/info
PUT /public/info-network
PUT /public/events
PUT /public/eventList
PUT /public/availBatteryModels
OPTIONS /public/availBatteryModels
OPTIONS /public/dynamic
OPTIONS /public/eventList
OPTIONS /public/events
OPTIONS /public/info
OPTIONS /public/info-network
OPTIONS /public/mnemoschema
OPTIONS /public/static
PUT /settings/admin/getinfo
PUT /settings/admin/setconf
PUT /settings/admin/checksetaccess
OPTIONS /settings/admin/checksetaccess
OPTIONS /settings/admin/getinfo
OPTIONS /settings/admin/setconf
[main(----) INF] Listening for requests on http://[::]:8888/
Failed to listen on 0.0.0.0:8888

we can see the endpoint /settings/admin/setconf added to router, but check output shows:

$ rdmd -version=check source/app.d
Not Found PUT /settings/admin/setconf
Not Found OPTIONS /settings/admin/setconf

it miss endpoints randomly (original code has more endpoints and missed other), I tried find rule but give up

@denizzzka
Copy link
Contributor

Reproduced on my system

Important: if web server isn't runs, this command:

$ rdmd -version=check source/app.d

returns nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants