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

nixos/dokuwiki: add test for login #94617

Merged
merged 1 commit into from Aug 5, 2020
Merged

Conversation

dadada
Copy link
Contributor

@dadada dadada commented Aug 3, 2020

Add a test to see if the login page is working when ACL is enabled. Follow-up to #94551

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added the 6.topic: nixos label Aug 3, 2020
@dadada dadada changed the title Dadada/dokuwiki nixos/dokuwiki: add test for login Aug 3, 2020
nixos/tests/dokuwiki.nix Outdated Show resolved Hide resolved
Copy link
Member

@1000101 1000101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are successful but IMHO they're not testing the actual login and don't fail because of the failed login message containing the keyword Admin. I've found this nice tutorial on how to test it: https://www.dokuwiki.org/tips:curl_login but there seems to be issues with the usersFile (permissions?), too.

While debugging, I've also noticed an error in the original service: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/web-apps/dokuwiki.nix#L98

There is users.auth.php instead of acl.auth.php

nixos/tests/dokuwiki.nix Outdated Show resolved Hide resolved
)
users_file.close()
machine.succeed(
"curl -sSfL --data 'u=admin' --data 'p=password' 'http://site2.local/doku.php?do=login' | grep 'Admin'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, it catches Admin from the error: User authentication is temporarily unavailable. If this situation persists, please inform your Wiki Admin.

Copy link
Member

@1000101 1000101 Aug 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I got it working... but I had to specify the usersFile like this:

let

  usersFile = pkgs.writeText "users.auth.php" ''
    admin:$2y$10$ijdBQMzSVV20SrKtCna8gue36vnsbVm2wItAXvdm876sshI4uwy6S:Admin:admin@example.test:user
  '';
...
in
{
...
    services.dokuwiki."site2.local" = {
      usersFile = toString usersFile;
...

and then check it like this:

...
    machine.succeed(
        "curl -d 'u=admin&p=password' --cookie-jar cjar http://site2.local/doku.php?do=login",
        "curl --cookie cjar --cookie-jar cjar http://site2.local/doku.php?do=login | grep 'Logged in as: <bdi>Admin</bdi>'",
    )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the cookie jar seems like the sensible option.

/tmp/users.auth.php did not work because the file was lost somewhere between the testScript and machine.succeed. Using machine.succeed to write the file works. I would prefer this in favor of the approach involving let usersFile, since in that case the file would be write-only, which is different from production.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Cookie jar can be used to accurately test if the login was successful.
Simply searching for the user name is not sufficient, since it is always
part of the returned page after login. The page should display a phrase
containing the username after login.
@1000101
Copy link
Member

1000101 commented Aug 4, 2020

@GrahamcOfBorg test dokuwiki

Copy link
Member

@1000101 1000101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!!!

@mmahut mmahut merged commit 258ca64 into NixOS:master Aug 5, 2020
@dadada dadada deleted the dadada/dokuwiki branch October 17, 2020 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants