@@ -149,9 +149,61 @@ describe MartenS3::Store do
149149 end
150150
151151 describe " #url" do
152- it " returns a URL constructed from the base URL" do
153- storage.url(" css/app.css" ).should contain " awscr-s3-test-"
154- storage.url(" css/app.css" ).should contain " css/app.css"
152+ it " returns a private URL constructed from the base URL" do
153+ uri = URI .parse(storage.url(" css/app.css" ))
154+
155+ uri.host.should eq URI .parse(ENV .fetch(" S3_ENDPOINT" , " http://127.0.0.1:9000" )).host
156+
157+ uri.path.should contain " #{ bucket_name } /css/app.css"
158+
159+ query = uri.query.not_nil!
160+
161+ query_params = URI ::Params .parse(query)
162+ query_params.has_key?(" X-Amz-Algorithm" ).should be_true
163+ query_params.has_key?(" X-Amz-Credential" ).should be_true
164+ query_params.has_key?(" X-Amz-Date" ).should be_true
165+ query_params[" X-Amz-Expires" ].should eq " 86400"
166+ query_params.has_key?(" X-Amz-SignedHeaders" ).should be_true
167+ query_params.has_key?(" X-Amz-Signature" ).should be_true
168+ end
169+
170+ it " returns a path-style public URL when `use_public_url` is true and `force_path_style` is enabled" do
171+ storage = MartenS3 ::Store .new(
172+ region: " unused" ,
173+ bucket: bucket_name,
174+ access_key: ENV .fetch(" S3_KEY" , " admin" ),
175+ secret_key: ENV .fetch(" S3_SECRET" , " password" ),
176+ endpoint: ENV .fetch(" S3_ENDPOINT" , " http://127.0.0.1:9000" ),
177+ force_path_style: true ,
178+ use_public_url: true ,
179+ )
180+ uri = URI .parse(storage.url(" css/app.css" ))
181+
182+ uri.host.should eq URI .parse(ENV .fetch(" S3_ENDPOINT" , " http://127.0.0.1:9000" )).host
183+
184+ uri.path.should eq " /#{ bucket_name } /css/app.css"
185+
186+ uri.query.should be_nil
187+ end
188+
189+ it " returns a virtual-host–style public URL when `use_public_url` is true and `force_path_style` is disabled" do
190+ storage = MartenS3 ::Store .new(
191+ region: " unused" ,
192+ bucket: bucket_name,
193+ access_key: ENV .fetch(" S3_KEY" , " admin" ),
194+ secret_key: ENV .fetch(" S3_SECRET" , " password" ),
195+ endpoint: ENV .fetch(" S3_ENDPOINT" , " http://127.0.0.1:9000" ),
196+ use_public_url: true ,
197+ )
198+ uri = URI .parse(storage.url(" css/app.css" ))
199+
200+ test_host = URI .parse(ENV .fetch(" S3_ENDPOINT" , " http://127.0.0.1:9000" )).host
201+
202+ uri.host.should eq " #{ bucket_name } .#{ test_host } "
203+
204+ uri.path.should eq " /css/app.css"
205+
206+ uri.query.should be_nil
155207 end
156208 end
157209
0 commit comments