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: 938a08aeb03719e98a6e118eb714b820798f91ff3d5e69cce65eeea3d8b243ca
4
- data.tar.gz: 9da7bbe8fa7ed6b92b90fa090f9ebf5ec67cb8945bace845494aa7638640b3ce
3
+ metadata.gz: 629e99af532182c8f167b2a5acd7f5a7561147bfc97a317d13ac0d345910297e
4
+ data.tar.gz: 3687a78229935a75a6af2e81567f6db49a215badbf2b09574fa643f8b6ad9a3d
5
5
  SHA512:
6
- metadata.gz: 86d05a06a42a06da4586d60bc80649cdb9f4cd98c26425d6528f7b121c2ca880b366bc12aeec7b20952bbc7129b2837dcd9261851bb960ddebd7de773e0b64b6
7
- data.tar.gz: 831783835b4ede6b590dd298e89f596c8c9ca417260e4ae490f8b6bbca576e07c7b5f89a490eb8b2b651e305a66b0c9dac7c526f0592d2fdef7f7337d70f6607
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
- [200, 422].include?(status) &&
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)
@@ -1,6 +1,6 @@
1
1
  module CopyTunerClient
2
2
  # Client version
3
- VERSION = '2.5.0'.freeze
3
+ VERSION = '2.5.1'.freeze
4
4
 
5
5
  # API version being used to communicate with the server
6
6
  API_VERSION = '2.0'.freeze
@@ -11,8 +11,7 @@ describe CopyTunerClient::CopyrayMiddleware do
11
11
 
12
12
  subject(:middleware) { described_class.new(app) }
13
13
 
14
- let(:app) { ->(_env) { [status, headers, [body]] } }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy_tuner_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SonicGarden