-
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.
- Loading branch information
1 parent
8e35a62
commit 8b4e627
Showing
2 changed files
with
63 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,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../.././test_helper' | ||
require "rack/test" | ||
|
||
module Puma | ||
module Acme | ||
class MiddlewareTest < Minitest::Test | ||
include ::Rack::Test::Methods | ||
|
||
class App | ||
def call(env) | ||
req = ::Rack::Request.new(env) | ||
[200, {}, ['request not handled by middleware']] | ||
end | ||
end | ||
|
||
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 FakeManager | ||
class Answer | ||
def initialize(value) | ||
@value = value | ||
end | ||
attr_reader :value | ||
end | ||
|
||
def answer(type:, token:) | ||
if token == 'good-token' | ||
Answer.new('42') | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
|
||
def app | ||
Puma::Acme::Middleware.new( | ||
App.new, | ||
manager: FakeManager.new | ||
) | ||
end | ||
end | ||
end | ||
end |