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:
parent
fa0ee16991
commit
fcdb5e4e34
@ -1,8 +1,9 @@
|
|||||||
|
autoload :Indieauth, File.expand_path('indieauth.rb', __dir__)
|
||||||
|
|
||||||
module Micropub
|
module Micropub
|
||||||
autoload :Webserver, File.expand_path('micropub/webserver.rb', __dir__)
|
|
||||||
autoload :Github, File.expand_path('micropub/github.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 :Post, File.expand_path('micropub/models/post.rb', __dir__)
|
||||||
autoload :PostJSONParser,
|
autoload :PostJSONParser,
|
||||||
File.expand_path('micropub/models/post_json_parser.rb', __dir__)
|
File.expand_path('micropub/models/post_json_parser.rb', __dir__)
|
||||||
|
autoload :Webserver, File.expand_path('micropub/webserver.rb', __dir__)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -58,7 +58,7 @@ module Micropub
|
|||||||
auth_type, auth_token = request.env["HTTP_AUTHORIZATION"]&.split(" ")
|
auth_type, auth_token = request.env["HTTP_AUTHORIZATION"]&.split(" ")
|
||||||
auth_token ||= params["access_token"]
|
auth_token ||= params["access_token"]
|
||||||
|
|
||||||
auth_type == "Bearer" && token.validate(auth_token)
|
token.validate(auth_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
def endpoints
|
def endpoints
|
||||||
|
|||||||
40
test/requests/auth_test.rb
Normal file
40
test/requests/auth_test.rb
Normal 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
|
||||||
@ -1,5 +1,5 @@
|
|||||||
require "request_helper"
|
require "request_helper"
|
||||||
require "micropub/indieauth"
|
require "indieauth"
|
||||||
require "micropub/github"
|
require "micropub/github"
|
||||||
|
|
||||||
describe "create post" do
|
describe "create post" do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user