Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

Fix tests for latest crystal version & add github actions #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/crystal.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dogruyolserdar@gmail.com>

crystal: 0.26.1
crystal: 1.2.2

license: MIT
2 changes: 1 addition & 1 deletion spec/s3/presigned/html_printer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Aws
end

Spec.after_each do
Timecop.reset
# Timecop.reset
end

it "generates the same html each call" do
Expand Down
6 changes: 3 additions & 3 deletions spec/s3/presigned/post_policy_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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
end

it "returns self" do
policy = Policy.new
policy.expiration(Time.now)
policy.expiration(Time.local)

policy.condition("test", "test").should eq policy
end
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions spec/s3/presigned/post_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Aws
end

Spec.after_each do
Timecop.reset
# Timecop.reset
end

describe "valid?" do
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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=")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion spec/s3/presigned/url_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/aws/s3/multipart_file_uploader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/aws/s3/paginators/list_object_v2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/aws/s3/presigned/form.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/aws/s3/presigned/post.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions src/aws/s3/presigned/url.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Aws

String.build do |str|
str << "https://"
str << request.host
str << request.hostname
str << request.resource
end
end
Expand All @@ -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
Expand Down