copy_tuner_client 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 629e99af532182c8f167b2a5acd7f5a7561147bfc97a317d13ac0d345910297e
|
|
4
|
+
data.tar.gz: 3687a78229935a75a6af2e81567f6db49a215badbf2b09574fa643f8b6ad9a3d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 79f2ca4118bc85c447d49f540ce1bfea082d47bb295d82b1b69a481685f7467d7f9afdec7ae87397d482f4953fef0e396116c8899a4ba0866db4d95b4d61d76e
|
|
7
|
+
data.tar.gz: 7a4df56a0368c1e0f25478949ebbb48f13582b0b1895fbdcb78bd776bc23edfe4391c59648c254c998a6ebd1327bdb0afb8c654149aa7307ae03b871210736fd
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# cf) xray-rails : xray/middleware.rb
|
|
2
2
|
|
|
3
|
+
require 'rack/utils'
|
|
3
4
|
require 'copy_tuner_client/copyray'
|
|
4
5
|
require 'copy_tuner_client/copyray/rewriter'
|
|
5
6
|
|
|
@@ -83,7 +84,10 @@ module CopyTunerClient
|
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def rewritable?(status, headers)
|
|
86
|
-
|
|
87
|
+
# NOTE: マーカーの注入側(copyray_injectable?)はステータスを見ないので、除去側もステータスで絞らない
|
|
88
|
+
# (絞るとリダイレクトやエラーページ(429 など)でマーカーが画面に露出する)。
|
|
89
|
+
# ボディを持たないステータスは書き換えで Content-Length が付くと Rack の仕様違反になるので除外する。
|
|
90
|
+
!Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.key?(status) &&
|
|
87
91
|
headers['Content-Type'] &&
|
|
88
92
|
(headers['Content-Type'].include?('text/html') || turbo_stream?(headers)) &&
|
|
89
93
|
!file?(headers)
|
|
@@ -11,8 +11,7 @@ describe CopyTunerClient::CopyrayMiddleware do
|
|
|
11
11
|
|
|
12
12
|
subject(:middleware) { described_class.new(app) }
|
|
13
13
|
|
|
14
|
-
let(:app) { ->(_env) { [
|
|
15
|
-
let(:status) { 200 }
|
|
14
|
+
let(:app) { ->(_env) { [200, headers, [body]] } }
|
|
16
15
|
|
|
17
16
|
before do
|
|
18
17
|
CopyTunerClient.configure do |configuration|
|
|
@@ -43,6 +42,37 @@ describe CopyTunerClient::CopyrayMiddleware do
|
|
|
43
42
|
end
|
|
44
43
|
end
|
|
45
44
|
|
|
45
|
+
context '200 以外のステータスで HTML を返すとき' do
|
|
46
|
+
let(:headers) { { 'Content-Type' => 'text/html' } }
|
|
47
|
+
let(:body) { "<html><body><p>#{marker('a.b')}Hello</p></body></html>" }
|
|
48
|
+
|
|
49
|
+
def call_with_status(status)
|
|
50
|
+
status_middleware = described_class.new(->(_env) { [status, headers, [body]] })
|
|
51
|
+
allow(status_middleware).to receive(:append_js) { |html, *| html }
|
|
52
|
+
status_middleware.call({}).last.join
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
[302, 429, 500].each do |status|
|
|
56
|
+
it "#{status} ではマーカーを data-copyray-key 属性に書き換え、トークンを除去する" do
|
|
57
|
+
result = call_with_status(status)
|
|
58
|
+
|
|
59
|
+
expect(result).to include('data-copyray-key="a.b"')
|
|
60
|
+
expect(result).not_to match CopyTunerClient::Copyray::Marker::SCAN_REGEXP
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
[204, 304].each do |status|
|
|
65
|
+
it "#{status} はボディを持たないのでボディもヘッダも変えずに通過させる" do
|
|
66
|
+
status_middleware = described_class.new(->(_env) { [status, headers, ['']] })
|
|
67
|
+
allow(status_middleware).to receive(:append_js) { |html, *| html }
|
|
68
|
+
_status, result_headers, response = status_middleware.call({})
|
|
69
|
+
|
|
70
|
+
expect(response.join).to eq ''
|
|
71
|
+
expect(result_headers).to eq('Content-Type' => 'text/html')
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
46
76
|
context 'turbo stream レスポンスのとき' do
|
|
47
77
|
let(:headers) { { 'Content-Type' => 'text/vnd.turbo-stream.html' } }
|
|
48
78
|
let(:body) do
|