-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from anchordotdev/middleware-wo-sinatra
Rewrite Middleware without sinatra
- Loading branch information
Showing
3 changed files
with
73 additions
and
6 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
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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../.././test_helper' | ||
require "rack/test" | ||
|
||
module Puma | ||
module Acme | ||
class MiddlewareTest < Minitest::Test | ||
include ::Rack::Test::Methods | ||
|
||
def test_it_returns_the_manager_answer_value_when_present | ||
get '/.well-known/acme-challenge/good-token' | ||
assert_equal '42', last_response.body | ||
assert_equal 'text/plain;charset=utf-8', last_response.headers['content-type'] | ||
end | ||
|
||
def test_it_passes_through_if_manager_provides_no_answer | ||
get '/.well-known/acme-challenge/unknown-token' | ||
assert_equal 'request not handled by middleware', last_response.body | ||
end | ||
|
||
def test_it_passes_unrecognized_requests_through | ||
get '/' | ||
assert_equal 'request not handled by middleware', last_response.body | ||
|
||
get '/any-other/path' | ||
assert_equal 'request not handled by middleware', last_response.body | ||
end | ||
|
||
class App | ||
def call(env) | ||
[200, {}, ['request not handled by middleware']] | ||
end | ||
end | ||
|
||
class FakeManager | ||
class Answer | ||
def initialize(value) | ||
@value = value | ||
end | ||
attr_reader :value | ||
end | ||
|
||
def answer(type:, token:) | ||
Answer.new('42') if token == 'good-token' | ||
end | ||
end | ||
|
||
def app | ||
Puma::Acme::Middleware.new( | ||
App.new, | ||
manager: FakeManager.new | ||
) | ||
end | ||
end | ||
end | ||
end |