-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46b3686
commit bc75f4d
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
port: 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "./spec_helper" | ||
|
||
describe Config do | ||
it "creates config if it does not exist" do | ||
tempfile = File.tempfile "mango-test-config" | ||
config = Config.load tempfile.path | ||
File.exists?(tempfile.path).should be_true | ||
tempfile.delete | ||
end | ||
it "correctly loads config" do | ||
config = Config.load "spec/asset/test-config.yml" | ||
config.port.should eq 3000 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require "spec" | ||
require "../src/context" | ||
require "../src/server" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require "./spec_helper" | ||
|
||
describe Storage do | ||
temp_config = File.tempfile "mango-test-config" | ||
temp_db = File.tempfile "mango-test-db" | ||
config = Config.load temp_config.path | ||
user_token = nil | ||
admin_token = nil | ||
|
||
it "creates DB at given path" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
File.exists?(temp_db.path).should be_true | ||
end | ||
it "deletes user" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
storage.delete_user "admin" | ||
end | ||
it "creates new user" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
storage.new_user "user", "123456", false | ||
storage.new_user "admin", "123456", true | ||
end | ||
it "verifies username/password combination" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
user_token = storage.verify_user "user", "123456" | ||
admin_token = storage.verify_user "admin", "123456" | ||
user_token.should_not be_nil | ||
admin_token.should_not be_nil | ||
end | ||
it "rejects duplicate username" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
expect_raises SQLite3::Exception, | ||
"UNIQUE constraint failed: users.username" do | ||
storage.new_user "admin", "123456", true | ||
end | ||
end | ||
it "verifies token" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
token = storage.verify_token user_token | ||
token.should eq "user" | ||
end | ||
it "verfies admin token" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
storage.verify_admin(admin_token).should be_true | ||
end | ||
it "rejects non-admin token" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
storage.verify_admin(user_token).should be_false | ||
end | ||
it "updates user" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
storage.update_user "admin", "admin", "654321", true | ||
token = storage.verify_user "admin", "654321" | ||
token.should eq admin_token | ||
end | ||
it "logs user out" do | ||
storage = Storage.new temp_db.path, MLogger.new config | ||
storage.logout user_token | ||
storage.logout admin_token | ||
storage.verify_token(user_token).should be_nil | ||
storage.verify_token(admin_token).should be_nil | ||
end | ||
|
||
temp_config.delete | ||
temp_db.delete | ||
end |