diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml new file mode 100644 index 0000000..ce9dbfc --- /dev/null +++ b/.github/workflows/crystal.yml @@ -0,0 +1,22 @@ +name: Crystal CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + container: + image: crystallang/crystal + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: shards install + - name: Run tests + run: crystal spec diff --git a/shard.yml b/shard.yml index ced5261..430c7b5 100644 --- a/shard.yml +++ b/shard.yml @@ -8,14 +8,13 @@ dependencies: development_dependencies: webmock: github: manastech/webmock.cr - version: 0.10.0 + branch: master timecop: - github: waterlink/timecop.cr - version: ~> 0.1.0 + github: crystal-community/timecop.cr authors: - Serdar Dogruyol -crystal: 0.26.1 +crystal: 1.2.2 license: MIT diff --git a/spec/s3/presigned/html_printer_spec.cr b/spec/s3/presigned/html_printer_spec.cr index 7da9914..171777e 100644 --- a/spec/s3/presigned/html_printer_spec.cr +++ b/spec/s3/presigned/html_printer_spec.cr @@ -9,7 +9,7 @@ module Aws end Spec.after_each do - Timecop.reset + # Timecop.reset end it "generates the same html each call" do diff --git a/spec/s3/presigned/post_policy_spec.cr b/spec/s3/presigned/post_policy_spec.cr index 936d64b..7cb2d87 100644 --- a/spec/s3/presigned/post_policy_spec.cr +++ b/spec/s3/presigned/post_policy_spec.cr @@ -7,7 +7,7 @@ module Aws describe "eq" do it "adds a field" do policy = Policy.new - policy.expiration(Time.now) + policy.expiration(Time.local) policy.condition("test", "test") policy.fields.size.should eq 1 @@ -15,7 +15,7 @@ module Aws it "returns self" do policy = Policy.new - policy.expiration(Time.now) + policy.expiration(Time.local) policy.condition("test", "test").should eq policy end @@ -24,7 +24,7 @@ module Aws describe "valid?" do it "returns true if expiration is set" do policy = Policy.new - policy.expiration(Time.now) + policy.expiration(Time.local) policy.valid?.should be_true end diff --git a/spec/s3/presigned/post_spec.cr b/spec/s3/presigned/post_spec.cr index 44a2fcf..92efc68 100644 --- a/spec/s3/presigned/post_spec.cr +++ b/spec/s3/presigned/post_spec.cr @@ -9,7 +9,7 @@ module Aws end Spec.after_each do - Timecop.reset + # Timecop.reset end describe "valid?" do @@ -19,7 +19,7 @@ module Aws aws_access_key: "test", aws_secret_key: "test" ) - post.build { |b| b.condition("bucket", "t"); b.expiration(Time.now) } + post.build { |b| b.condition("bucket", "t"); b.expiration(Time.utc) } post.valid?.should be_true end @@ -30,7 +30,7 @@ module Aws aws_access_key: "test", aws_secret_key: "test" ) - post.build { |b| b.expiration(Time.now) } + post.build { |b| b.expiration(Time.utc) } post.valid?.should be_false end @@ -148,7 +148,7 @@ module Aws aws_access_key: "test", aws_secret_key: "test" ) - post.build { |b| b.expiration(Time.now) } + post.build { |b| b.expiration(Time.utc) } expect_raises(Exception) do post.url @@ -161,7 +161,7 @@ module Aws aws_access_key: "test", aws_secret_key: "test" ) - post.build { |b| b.expiration(Time.now); b.condition("bucket", "test") } + post.build { |b| b.expiration(Time.utc); b.condition("bucket", "test") } post.url.should eq("http://test.s3.amazonaws.com") end @@ -174,7 +174,7 @@ module Aws aws_access_key: "test", aws_secret_key: "test" ) - post.build { |b| b.expiration(Time.now) } + post.build { |b| b.expiration(Time.utc) } post.fields.should be_a(FieldCollection) end @@ -189,7 +189,7 @@ module Aws signer: :v2 ) policy = nil - post.build { |p| p.expiration(Time.now); policy = p } + post.build { |p| p.expiration(Time.utc); policy = p } policy.should be_a(Policy) policy.as(Policy).fields["Signature"].should eq("vI0Km7fxOL7B9BunXFKM2/GvS1A=") @@ -202,7 +202,7 @@ module Aws aws_secret_key: "test" ) policy = nil - post.build { |p| p.expiration(Time.now); policy = p } + post.build { |p| p.expiration(Time.utc); policy = p } policy.should be_a(Policy) policy.as(Policy).fields["x-amz-signature"].should eq("7dc0bf8fe1dcc2344f8ceaf3148a8898fbac6f074ccbe4edfbfac545be693add") diff --git a/spec/s3/presigned/url_spec.cr b/spec/s3/presigned/url_spec.cr index dbac4d2..10cf0aa 100644 --- a/spec/s3/presigned/url_spec.cr +++ b/spec/s3/presigned/url_spec.cr @@ -76,7 +76,7 @@ module Aws end it "generates a correct url for v4" do - Timecop.freeze(Time.new(2013, 5, 24)) do + Timecop.freeze(Time.utc(2013, 5, 24)) do options = Url::Options.new( region: "us-east-1", aws_access_key: "AKIAIOSFODNN7EXAMPLE", diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index aed7a2f..13638b3 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -3,11 +3,11 @@ require "timecop" require "webmock" require "./s3/fixtures" -struct Time - def self.utc_now - Timecop.now - end -end +#struct Time +# def self.utc_now +# Timecop.now +# end +#end Spec.before_each do WebMock.reset diff --git a/src/aws/s3/multipart_file_uploader.cr b/src/aws/s3/multipart_file_uploader.cr index 4408536..970c7b7 100644 --- a/src/aws/s3/multipart_file_uploader.cr +++ b/src/aws/s3/multipart_file_uploader.cr @@ -57,8 +57,8 @@ module Aws::S3 end end - private def compute_default_part_size(source_size) - [(source_size / 10_000).ceil, 5 * 1024 * 1024].max + private def compute_default_part_size(source_size) : Int32 + [(source_size / 10_000).ceil, 5 * 1024 * 1024].max.to_i end private def part_size(total_size, part_size, offset) diff --git a/src/aws/s3/paginators/list_object_v2.cr b/src/aws/s3/paginators/list_object_v2.cr index 26d867f..f3eb5e3 100644 --- a/src/aws/s3/paginators/list_object_v2.cr +++ b/src/aws/s3/paginators/list_object_v2.cr @@ -30,7 +30,7 @@ module Aws::S3::Paginator # :nodoc: private def query_string - @params.map { |k, v| "#{k}=#{URI.escape(v.to_s)}" }.join("&") + @params.map { |k, v| "#{k}=#{URI.encode_www_form(v.to_s)}" }.join("&") end end end diff --git a/src/aws/s3/presigned/form.cr b/src/aws/s3/presigned/form.cr index ed14b25..ae6a144 100644 --- a/src/aws/s3/presigned/form.cr +++ b/src/aws/s3/presigned/form.cr @@ -16,7 +16,7 @@ module Aws # # ``` # Aws::S3::Presigned::Form.build("us-east-1", "aws key", "aws secret") do |form| - # form.expiration(Time.utc_now.to_unix + 1000) + # form.expiration(Time.utc.to_unix + 1000) # form.condition("bucket", "my bucket") # form.condition("acl", "public-read") # form.condition("key", "helloworld.png") diff --git a/src/aws/s3/presigned/post.cr b/src/aws/s3/presigned/post.cr index 0bdf6b2..56a25e4 100644 --- a/src/aws/s3/presigned/post.cr +++ b/src/aws/s3/presigned/post.cr @@ -67,7 +67,7 @@ module Aws private def add_fields_before_sign case @signer when :v4 - time = Time.utc_now + time = Time.utc @policy.condition("x-amz-credential", credential_scope(time)) @policy.condition("x-amz-algorithm", Awscr::Signer::ALGORITHM) @policy.condition("x-amz-date", time.to_s("%Y%m%dT%H%M%SZ")) diff --git a/src/aws/s3/presigned/url.cr b/src/aws/s3/presigned/url.cr index 9d02b2f..55b32f9 100644 --- a/src/aws/s3/presigned/url.cr +++ b/src/aws/s3/presigned/url.cr @@ -30,7 +30,7 @@ module Aws String.build do |str| str << "https://" - str << request.host + str << request.hostname str << request.resource end end @@ -56,7 +56,7 @@ module Aws if @options.signer_version == :v4 request.query_params.add("X-Amz-Expires", @options.expires.to_s) else - request.query_params.add("Expires", (Time.utc_now.to_unix + Time.unix(@options.expires).to_unix).to_s) + request.query_params.add("Expires", (Time.utc.to_unix + Time.unix(@options.expires).to_unix).to_s) end request