1
0
mirror of https://github.com/danbee/micropub.git synced 2025-03-04 08:59:13 +00:00
micropub/test/requests/auth_test.rb
2022-08-19 19:07:28 -05:00

40 lines
943 B
Ruby

require "request_helper"
describe "auth" do
before(:each) do
@auth_token = "123abc"
endpoints = { 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", {
content: "Hello, World!"
}
assert last_response.unauthorized?
end
it "authenticates with a header" do
header "Authorization", "Bearer #{@auth_token}"
post "/micropub", {
content: "Hello, World!"
}
assert last_response.accepted?
end
it "authenticates with a form param" do
post "/micropub", {
access_token: @auth_token,
content: "Hello, World!"
}
assert last_response.accepted?
end
end