1
0
mirror of https://github.com/danbee/micropub.git synced 2025-03-04 08:59:13 +00:00

Add tests for authorization

This commit is contained in:
Daniel Barber 2019-11-16 22:58:39 -05:00
parent fa0ee16991
commit fcdb5e4e34
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
7 changed files with 45 additions and 4 deletions

View File

@ -1,8 +1,9 @@
autoload :Indieauth, File.expand_path('indieauth.rb', __dir__)
module Micropub
autoload :Webserver, File.expand_path('micropub/webserver.rb', __dir__)
autoload :Github, File.expand_path('micropub/github.rb', __dir__)
autoload :Indieauth, File.expand_path('micropub/indieauth.rb', __dir__)
autoload :Post, File.expand_path('micropub/models/post.rb', __dir__)
autoload :PostJSONParser,
File.expand_path('micropub/models/post_json_parser.rb', __dir__)
autoload :Webserver, File.expand_path('micropub/webserver.rb', __dir__)
end

View File

@ -58,7 +58,7 @@ module Micropub
auth_type, auth_token = request.env["HTTP_AUTHORIZATION"]&.split(" ")
auth_token ||= params["access_token"]
auth_type == "Bearer" && token.validate(auth_token)
token.validate(auth_token)
end
def endpoints

View File

@ -0,0 +1,40 @@
require "request_helper"
describe "auth" do
before(:each) do
@auth_token = "123abc"
endpoints = mock("Indieauth::Endpoints")
endpoints.stubs(:token_endpoint)
Indieauth::Endpoints.stubs(:new).returns endpoints
Indieauth::Token.any_instance.stubs(:validate).returns(false)
Indieauth::Token.any_instance.stubs(:validate).
with(@auth_token).returns(true)
Micropub::Github.any_instance.stubs(:post!).returns(true)
end
it "rejects authentication without a token" do
post "/micropub/main", {
content: "Hello, World!"
}
assert last_response.unauthorized?
end
it "authenticates with a header" do
header "Authorization", "Bearer #{@auth_token}"
post "/micropub/main", {
content: "Hello, World!"
}
assert last_response.accepted?
end
it "authenticates with a form param" do
post "/micropub/main", {
access_token: @auth_token,
content: "Hello, World!"
}
assert last_response.accepted?
end
end

View File

@ -1,5 +1,5 @@
require "request_helper"
require "micropub/indieauth"
require "indieauth"
require "micropub/github"
describe "create post" do