Merge branch 'master' into no-vibe-default-main
Fixes the issues discussed in !5
This commit is contained in:
commit
0cab33bcb3
3 changed files with 23 additions and 11 deletions
6
dub.json
6
dub.json
|
@ -4,9 +4,14 @@
|
||||||
"Johannes Loher"
|
"Johannes Loher"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"botan": "~>1.12.9",
|
||||||
"vibe-d": "~>0.8.1",
|
"vibe-d": "~>0.8.1",
|
||||||
|
"vibe-d:tls": "~>0.8.1",
|
||||||
"poodinis": "~>8.0.1"
|
"poodinis": "~>8.0.1"
|
||||||
},
|
},
|
||||||
|
"subConfigurations": {
|
||||||
|
"vibe-d:tls": "botan"
|
||||||
|
},
|
||||||
"description": "A simple webapplication to edit and view calendar entries",
|
"description": "A simple webapplication to edit and view calendar entries",
|
||||||
"copyright": "Copyright © 2017, Johannes Loher",
|
"copyright": "Copyright © 2017, Johannes Loher",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -21,6 +26,7 @@
|
||||||
"targetType": "executable",
|
"targetType": "executable",
|
||||||
"preBuildCommands": ["dub run unit-threaded -c gen_ut_main -- -f generated/ut.d test"],
|
"preBuildCommands": ["dub run unit-threaded -c gen_ut_main -- -f generated/ut.d test"],
|
||||||
"mainSourceFile": "generated/ut.d",
|
"mainSourceFile": "generated/ut.d",
|
||||||
|
"excludedSourceFiles": ["source/calendarwebapp/app.d"],
|
||||||
"sourcePaths": ["test"],
|
"sourcePaths": ["test"],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"unit-threaded": "~>0.7.31"
|
"unit-threaded": "~>0.7.31"
|
||||||
|
|
|
@ -2,7 +2,6 @@ module calendarwebapp.authenticator;
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
import vibe.data.bson : Bson;
|
|
||||||
import vibe.db.mongo.collection : MongoCollection;
|
import vibe.db.mongo.collection : MongoCollection;
|
||||||
|
|
||||||
interface Authenticator
|
interface Authenticator
|
||||||
|
@ -19,8 +18,15 @@ private:
|
||||||
public:
|
public:
|
||||||
bool checkUser(string username, string password) @safe
|
bool checkUser(string username, string password) @safe
|
||||||
{
|
{
|
||||||
auto result = users.findOne(["username" : username, "password" : password]);
|
import botan.passhash.bcrypt : checkBcrypt;
|
||||||
return result != Bson(null);
|
import vibe.data.bson : Bson;
|
||||||
|
|
||||||
|
auto result = users.findOne(["username" : username]);
|
||||||
|
/* checkBcrypt should be called using vibe.core.concurrency.async to
|
||||||
|
avoid blocking, but https://github.com/vibe-d/vibe.d/issues/1521 is
|
||||||
|
blocking this */
|
||||||
|
return (result != Bson(null)) && (() @trusted => checkBcrypt(password,
|
||||||
|
result["password"].get!string))();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import poodinis;
|
||||||
import unit_threaded.mock;
|
import unit_threaded.mock;
|
||||||
import unit_threaded.should;
|
import unit_threaded.should;
|
||||||
|
|
||||||
import vibe.data.bson : Bson;
|
import vibe.data.bson : Bson, BsonObjectID;
|
||||||
|
|
||||||
interface Collection
|
interface Collection
|
||||||
{
|
{
|
||||||
|
@ -41,13 +41,13 @@ public:
|
||||||
container.register!(Authenticator, MongoDBAuthenticator!(Collection))(
|
container.register!(Authenticator, MongoDBAuthenticator!(Collection))(
|
||||||
RegistrationOption.doNotAddConcreteTypeRegistration);
|
RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||||
|
|
||||||
collection.returnValue!"findOne"(Bson(true), Bson(null));
|
auto userBson = Bson(["_id" : Bson(BsonObjectID.fromString("5988ef4ae6c19089a1a53b79")), "username" : Bson("foo"),
|
||||||
collection.expect!"findOne"(["username" : "", "password" : ""]);
|
"password" : Bson("$2a$10$9LBqOZV99ARiE4Nx.2b7GeYfqk2.0A32PWGu2cRGyW2hRJ0xeDfnO")]);
|
||||||
collection.expect!"findOne"(["username" : "foo", "password" : "bar"]);
|
|
||||||
|
collection.returnValue!"findOne"(Bson(null), userBson, userBson);
|
||||||
|
|
||||||
auto authenticator = container.resolve!(Authenticator);
|
auto authenticator = container.resolve!(Authenticator);
|
||||||
authenticator.checkUser("", "").shouldBeTrue;
|
authenticator.checkUser("", "").shouldBeFalse;
|
||||||
authenticator.checkUser("foo", "bar").shouldBeFalse;
|
authenticator.checkUser("foo", "bar").shouldBeTrue;
|
||||||
|
authenticator.checkUser("foo", "baz").shouldBeFalse;
|
||||||
collection.verify;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue