aws_cf_signer 0.1.1 → 0.1.2

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.
@@ -0,0 +1,79 @@
1
+ # aws_cf_signer
2
+
3
+ Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here:
4
+ http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html
5
+
6
+ ## Installation
7
+
8
+ In your Gemfile.
9
+
10
+ gem 'aws_cf_signer'
11
+
12
+ Or on your system.
13
+
14
+ gem install aws_cf_signer
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ # Pass in path to the private CloudFront key from AWS
20
+ signer = AwsCfSigner.new('/path/to/my/pk-1234567890.pem')
21
+
22
+ # If the key filename doesn't contain the key_pair_id (as it usually does from AWS), pass that in as the second arg
23
+ signer = AwsCfSigner.new('/path/to/my/private-key.pem', '1234567890')
24
+
25
+ # expiration date is required
26
+ # See Example Canned Policy at above AWS doc link
27
+ url = signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => 'Sat, 14 Nov 2009 22:20:00 GMT')
28
+
29
+ # You can also use a Time object
30
+ url = signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => Time.now + 3600)
31
+
32
+ # Custom Policies
33
+
34
+ # See Example Custom Policy 1 at above AWS doc link
35
+ url = signer.sign('http://d604721fxaaqy9.cloudfront.net/training/orientation.avi',
36
+ :ending => 'Sat, 14 Nov 2009 22:20:00 GMT',
37
+ :resource => 'http://d604721fxaaqy9.cloudfront.net/training/*',
38
+ :ip_range => '145.168.143.0/24'
39
+ )
40
+
41
+ # See Example Custom Policy 2 at above AWS doc link
42
+ url = signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz',
43
+ :starting => 'Thu, 30 Apr 2009 06:43:10 GMT',
44
+ :ending => 'Fri, 16 Oct 2009 06:31:56 GMT',
45
+ :resource => 'http://*',
46
+ :ip_range => '216.98.35.1/32'
47
+ )
48
+
49
+ # You can also pass in a path to a policy file
50
+ # This will supersede any other policy options
51
+ url = signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz',
52
+ :policy_file => '/path/to/policy/file.txt'
53
+ )
54
+ ```
55
+
56
+ See the test/test_aws_cf_signer.rb file for more examples.
57
+
58
+ ## Note on Patches/Pull Requests
59
+
60
+ * Fork the project.
61
+ * Make your feature addition or bug fix.
62
+ * Add tests for it. This is important so I don't break it in a
63
+ future version unintentionally.
64
+ * Commit, do not mess with rakefile, version, or history.
65
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
66
+ * Send me a pull request. Bonus points for topic branches.
67
+
68
+ ## Attributions
69
+
70
+ Parts of signing code taken from a question on Stack Overflow asked by Ben Wiseley, and answered by Blaz Lipuscek and Manual M:
71
+
72
+ * http://stackoverflow.com/questions/2632457/create-signed-urls-for-cloudfront-with-ruby
73
+ * http://stackoverflow.com/users/315829/ben-wiseley
74
+ * http://stackoverflow.com/users/267804/blaz-lipuscek
75
+ * http://stackoverflow.com/users/327914/manuel-m
76
+
77
+ ## License
78
+
79
+ aws_cf_signer is distributed under the MIT License, copyright © 2010 STL
@@ -22,10 +22,10 @@ class AwsCfSigner
22
22
  "#{url_to_sign}#{separator}Policy=#{encode_policy(policy)}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
23
23
  else
24
24
  raise ArgumentError.new("'ending' argument is required") if policy_options[:ending].nil?
25
- if policy_options.keys.size == 1
25
+ if policy_options.keys == [:ending] || policy_options.keys.sort == [:ending, :resource]
26
26
  # Canned Policy - shorter URL
27
27
  expires_at = epoch_time(policy_options[:ending])
28
- policy = %({"Statement":[{"Resource":"#{url_to_sign}","Condition":{"DateLessThan":{"AWS:EpochTime":#{expires_at}}}}]})
28
+ policy = %({"Statement":[{"Resource":"#{policy_options[:resource] || url_to_sign}","Condition":{"DateLessThan":{"AWS:EpochTime":#{expires_at}}}}]})
29
29
  "#{url_to_sign}#{separator}Expires=#{expires_at}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
30
30
  else
31
31
  # Custom Policy
@@ -39,7 +39,7 @@ class AwsCfSigner
39
39
  def generate_custom_policy(resource, options)
40
40
  conditions = ["\"DateLessThan\":{\"AWS:EpochTime\":#{epoch_time(options[:ending])}}"]
41
41
  conditions << "\"DateGreaterThan\":{\"AWS:EpochTime\":#{epoch_time(options[:starting])}}" if options[:starting]
42
- conditions << "\"IpAddress\":{\"AWS:SourceIp\":\"#{options[:ip_range]}\"" if options[:ip_range]
42
+ conditions << "\"IpAddress\":{\"AWS:SourceIp\":\"#{options[:ip_range] || '0.0.0.0/0'}\""
43
43
  %({"Statement":[{"Resource":"#{resource}","Condition":{#{conditions.join(',')}}}}]})
44
44
  end
45
45
 
@@ -0,0 +1,3 @@
1
+ class AwsCfSigner
2
+ VERSION = "0.1.2"
3
+ end
metadata CHANGED
@@ -1,90 +1,97 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: aws_cf_signer
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
4
5
  prerelease:
5
- version: 0.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Dylan Vaughn
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-02-08 00:00:00 -08:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: thoughtbot-shoulda
12
+ date: 2013-08-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '10.1'
22
+ type: :development
18
23
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '10.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: thoughtbot-shoulda
32
+ requirement: !ruby/object:Gem::Requirement
20
33
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
25
38
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: yard
29
39
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
31
49
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
36
54
  type: :development
37
- version_requirements: *id002
38
- description: "Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here: http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html"
39
- email: dylan.vaughn@stlondemand.com
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ description:
63
+ email:
64
+ - dylan.vaughn@stlondemand.com
40
65
  executables: []
41
-
42
66
  extensions: []
43
-
44
- extra_rdoc_files:
45
- - README.rdoc
46
- files:
47
- - .document
48
- - README.rdoc
49
- - Rakefile
50
- - VERSION
51
- - aws_cf_signer.gemspec
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/aws_cf_signer/version.rb
52
70
  - lib/aws_cf_signer.rb
53
- - test/fixtures/README
54
- - test/fixtures/custom_policy1
55
- - test/fixtures/custom_policy2
56
- - test/fixtures/pk-PK123456789754.pem
57
- - test/fixtures/rsa-PK123456789754.pem
58
- - test/helper.rb
59
- - test/test_aws_cf_signer.rb
60
- has_rdoc: true
61
- homepage: http://github.com/stlondemand/aws_cf_signer
71
+ - README.md
72
+ homepage: https://github.com/stlondemand/aws_cf_signer?source=c
62
73
  licenses: []
63
-
64
74
  post_install_message:
65
75
  rdoc_options: []
66
-
67
- require_paths:
76
+ require_paths:
68
77
  - lib
69
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
70
79
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
75
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
85
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
81
90
  requirements: []
82
-
83
91
  rubyforge_project:
84
- rubygems_version: 1.5.0
92
+ rubygems_version: 1.8.23
85
93
  signing_key:
86
94
  specification_version: 3
87
- summary: Ruby gem for signing AWS Cloudfront URLs for serving private content
88
- test_files:
89
- - test/helper.rb
90
- - test/test_aws_cf_signer.rb
95
+ summary: Ruby gem for signing AWS Cloudfront URLs for serving private content.
96
+ test_files: []
97
+ has_rdoc:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
@@ -1,70 +0,0 @@
1
- = aws_cf_signer
2
-
3
- Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here:
4
-
5
- * http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html
6
-
7
- == Installation
8
-
9
- gem install aws_cf_signer
10
-
11
- == Usage
12
-
13
- # Pass in path to the private CloudFront key from AWS
14
- signer = AwsCfSigner.new('/path/to/my/pk-1234567890.pem')
15
-
16
- # If the key filename doesn't contain the key_pair_id (as it usually does from AWS), pass that in as the second arg
17
- signer = AwsCfSigner.new('/path/to/my/private-key.pem', '1234567890')
18
-
19
- # expiration date is required
20
- # See Example Canned Policy at above AWS doc link
21
- url = signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => 'Sat, 14 Nov 2009 22:20:00 GMT')
22
-
23
- # You can also use a Time object
24
- url = signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => Time.now + 3600)
25
-
26
- # Custom Policies
27
-
28
- # See Example Custom Policy 1 at above AWS doc link
29
- url = signer.sign('http://d604721fxaaqy9.cloudfront.net/training/orientation.avi',
30
- :ending => 'Sat, 14 Nov 2009 22:20:00 GMT',
31
- :resource => 'http://d604721fxaaqy9.cloudfront.net/training/*',
32
- :ip_range => '145.168.143.0/24'
33
- )
34
-
35
- # See Example Custom Policy 2 at above AWS doc link
36
- url = signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz',
37
- :starting => 'Thu, 30 Apr 2009 06:43:10 GMT',
38
- :ending => 'Fri, 16 Oct 2009 06:31:56 GMT',
39
- :resource => 'http://*',
40
- :ip_range => '216.98.35.1/32'
41
- )
42
-
43
- # You can also pass in a path to a policy file
44
- # This will supersede any other policy options
45
- url = signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz', :policy_file => '/path/to/policy/file.txt')
46
-
47
- See the test/test_aws_cf_signer.rb file for more examples.
48
-
49
- == Note on Patches/Pull Requests
50
-
51
- * Fork the project.
52
- * Make your feature addition or bug fix.
53
- * Add tests for it. This is important so I don't break it in a
54
- future version unintentionally.
55
- * Commit, do not mess with rakefile, version, or history.
56
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
57
- * Send me a pull request. Bonus points for topic branches.
58
-
59
- == Attributions
60
-
61
- Parts of signing code taken from a question on Stack Overflow asked by Ben Wiseley, and answered by Blaz Lipuscek and Manual M:
62
-
63
- * http://stackoverflow.com/questions/2632457/create-signed-urls-for-cloudfront-with-ruby
64
- * http://stackoverflow.com/users/315829/ben-wiseley
65
- * http://stackoverflow.com/users/267804/blaz-lipuscek
66
- * http://stackoverflow.com/users/327914/manuel-m
67
-
68
- == License
69
-
70
- aws_cf_signer is distributed under the MIT License, copyright © 2010 STL
data/Rakefile DELETED
@@ -1,53 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "aws_cf_signer"
8
- gem.summary = %Q{Ruby gem for signing AWS Cloudfront URLs for serving private content}
9
- gem.description = %Q{Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here: http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html}
10
- gem.email = "dylan.vaughn@stlondemand.com"
11
- gem.homepage = "http://github.com/stlondemand/aws_cf_signer"
12
- gem.authors = ["Dylan Vaughn"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- gem.add_development_dependency "yard", ">= 0"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
21
-
22
- require 'rake/testtask'
23
- Rake::TestTask.new(:test) do |test|
24
- test.libs << 'lib' << 'test'
25
- test.pattern = 'test/**/test_*.rb'
26
- test.verbose = true
27
- end
28
-
29
- begin
30
- require 'rcov/rcovtask'
31
- Rcov::RcovTask.new do |test|
32
- test.libs << 'test'
33
- test.pattern = 'test/**/test_*.rb'
34
- test.verbose = true
35
- end
36
- rescue LoadError
37
- task :rcov do
38
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
- end
40
- end
41
-
42
- task :test => :check_dependencies
43
-
44
- task :default => :test
45
-
46
- begin
47
- require 'yard'
48
- YARD::Rake::YardocTask.new
49
- rescue LoadError
50
- task :yardoc do
51
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
52
- end
53
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
@@ -1,57 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{aws_cf_signer}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dylan Vaughn"]
12
- s.date = %q{2011-02-08}
13
- s.description = %q{Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here: http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html}
14
- s.email = %q{dylan.vaughn@stlondemand.com}
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".document",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "aws_cf_signer.gemspec",
24
- "lib/aws_cf_signer.rb",
25
- "test/fixtures/README",
26
- "test/fixtures/custom_policy1",
27
- "test/fixtures/custom_policy2",
28
- "test/fixtures/pk-PK123456789754.pem",
29
- "test/fixtures/rsa-PK123456789754.pem",
30
- "test/helper.rb",
31
- "test/test_aws_cf_signer.rb"
32
- ]
33
- s.homepage = %q{http://github.com/stlondemand/aws_cf_signer}
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.5.0}
36
- s.summary = %q{Ruby gem for signing AWS Cloudfront URLs for serving private content}
37
- s.test_files = [
38
- "test/helper.rb",
39
- "test/test_aws_cf_signer.rb"
40
- ]
41
-
42
- if s.respond_to? :specification_version then
43
- s.specification_version = 3
44
-
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
- s.add_development_dependency(%q<yard>, [">= 0"])
48
- else
49
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
- s.add_dependency(%q<yard>, [">= 0"])
51
- end
52
- else
53
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
- s.add_dependency(%q<yard>, [">= 0"])
55
- end
56
- end
57
-
@@ -1,5 +0,0 @@
1
- The example keys and policies are from this page:
2
-
3
- http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html
4
-
5
- renamed from private-key.pem and public-key.pem to reflect the normal way AWS names these keys.
@@ -1,9 +0,0 @@
1
- {
2
- "Statement": [{
3
- "Resource":"http://d604721fxaaqy9.cloudfront.net/training/*",
4
- "Condition":{
5
- "IpAddress":{"AWS:SourceIp":"145.168.143.0/24"},
6
- "DateLessThan":{"AWS:EpochTime":1258237200}
7
- }
8
- }]
9
- }
@@ -1,10 +0,0 @@
1
- {
2
- "Statement": [{
3
- "Resource":"http://*",
4
- "Condition":{
5
- "IpAddress":{"AWS:SourceIp":"216.98.35.1/32"},
6
- "DateGreaterThan":{"AWS:EpochTime":1241073790},
7
- "DateLessThan":{"AWS:EpochTime":1255674716}
8
- }
9
- }]
10
- }
@@ -1,15 +0,0 @@
1
- -----BEGIN RSA PRIVATE KEY-----
2
- MIICXQIBAAKBgQDA7ki9gI/lRygIoOjV1yymgx6FYFlzJ+z1ATMaLo57nL57AavW
3
- hb68HYY8EA0GJU9xQdMVaHBogF3eiCWYXSUZCWM/+M5+ZcdQraRRScucmn6g4EvY
4
- 2K4W2pxbqH8vmUikPxir41EeBPLjMOzKvbzzQy9e/zzIQVREKSp/7y1mywIDAQAB
5
- AoGABc7mp7XYHynuPZxChjWNJZIq+A73gm0ASDv6At7F8Vi9r0xUlQe/v0AQS3yc
6
- N8QlyR4XMbzMLYk3yjxFDXo4ZKQtOGzLGteCU2srANiLv26/imXA8FVidZftTAtL
7
- viWQZBVPTeYIA69ATUYPEq0a5u5wjGyUOij9OWyuy01mbPkCQQDluYoNpPOekQ0Z
8
- WrPgJ5rxc8f6zG37ZVoDBiexqtVShIF5W3xYuWhW5kYb0hliYfkq15cS7t9m95h3
9
- 1QJf/xI/AkEA1v9l/WN1a1N3rOK4VGoCokx7kR2SyTMSbZgF9IWJNOugR/WZw7HT
10
- njipO3c9dy1Ms9pUKwUF46d7049ck8HwdQJARgrSKuLWXMyBH+/l1Dx/I4tXuAJI
11
- rlPyo+VmiOc7b5NzHptkSHEPfR9s1OK0VqjknclqCJ3Ig86OMEtEFBzjZQJBAKYz
12
- 470hcPkaGk7tKYAgP48FvxRsnzeooptURW5E+M+PQ2W9iDPPOX9739+Xi02hGEWF
13
- B0IGbQoTRFdE4VVcPK0CQQCeS84lODlC0Y2BZv2JxW3Osv/WkUQ4dslfAQl1T303
14
- 7uwwr7XTroMv8dIFQIPreoPhRKmd/SbJzbiKfS/4QDhU
15
- -----END RSA PRIVATE KEY-----
@@ -1,6 +0,0 @@
1
- -----BEGIN PUBLIC KEY-----
2
- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDA7ki9gI/lRygIoOjV1yymgx6F
3
- YFlzJ+z1ATMaLo57nL57AavWhb68HYY8EA0GJU9xQdMVaHBogF3eiCWYXSUZCWM/
4
- +M5+ZcdQraRRScucmn6g4EvY2K4W2pxbqH8vmUikPxir41EeBPLjMOzKvbzzQy9e
5
- /zzIQVREKSp/7y1mywIDAQAB
6
- -----END PUBLIC KEY-----
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'aws_cf_signer'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,66 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'helper'
3
-
4
- class TestAwsCfSigner < Test::Unit::TestCase
5
- context "CloudFront Signing" do
6
- setup do
7
- @cf_signer = AwsCfSigner.new(File.join(File.dirname(__FILE__), 'fixtures', 'pk-PK123456789754.pem'))
8
- end
9
-
10
- context "Initialization and Error Checking" do
11
- should "be able to extract the key pair id from the filename of a key straight from AWS" do
12
- assert_equal @cf_signer.extract_key_pair_id('/path/to/my/key/pk-THEKEYID.pem'), 'THEKEYID'
13
- end
14
-
15
- should "be able to tell you the key pair id" do
16
- assert_equal @cf_signer.key_pair_id, 'PK123456789754'
17
- end
18
-
19
- should "be able to make a string 'Url-Safe'" do
20
- assert_equal(
21
- @cf_signer.url_safe("Test+String_~ =Something/Weird"),
22
- "Test-String_~_Something~Weird"
23
- )
24
- end
25
- end
26
-
27
- context "Example Canned Policy" do
28
- should "generate the correct signature" do
29
- assert_equal(
30
- @cf_signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => 'Sat, 14 Nov 2009 22:20:00 GMT'),
31
- 'http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes&Expires=1258237200&Signature=Nql641NHEUkUaXQHZINK1FZ~SYeUSoBJMxjdgqrzIdzV2gyEXPDNv0pYdWJkflDKJ3xIu7lbwRpSkG98NBlgPi4ZJpRRnVX4kXAJK6tdNx6FucDB7OVqzcxkxHsGFd8VCG1BkC-Afh9~lOCMIYHIaiOB6~5jt9w2EOwi6sIIqrg_&Key-Pair-Id=PK123456789754'
32
- )
33
- end
34
- end
35
-
36
- context "Custom Policies from files" do
37
- should "generate custom policy 1 correctly" do
38
- assert_equal(
39
- @cf_signer.sign('http://d604721fxaaqy9.cloudfront.net/training/orientation.avi', :policy_file => File.join(File.dirname(__FILE__), 'fixtures', 'custom_policy1')),
40
- 'http://d604721fxaaqy9.cloudfront.net/training/orientation.avi?Policy=eyAKICAgIlN0YXRlbWVudCI6IFt7IAogICAgICAiUmVzb3VyY2UiOiJodHRwOi8vZDYwNDcyMWZ4YWFxeTkuY2xvdWRmcm9udC5uZXQvdHJhaW5pbmcvKiIsIAogICAgICAiQ29uZGl0aW9uIjp7IAogICAgICAgICAiSXBBZGRyZXNzIjp7IkFXUzpTb3VyY2VJcCI6IjE0NS4xNjguMTQzLjAvMjQifSwgCiAgICAgICAgICJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI1ODIzNzIwMH0gICAgICAKICAgICAgfSAKICAgfV0gCn0K&Signature=cPFtRKvUfYNYmxek6ZNs6vgKEZP6G3Cb4cyVt~FjqbHOnMdxdT7eT6pYmhHYzuDsFH4Jpsctke2Ux6PCXcKxUcTIm8SO4b29~1QvhMl-CIojki3Hd3~Unxjw7Cpo1qRjtvrimW0DPZBZYHFZtiZXsaPt87yBP9GWnTQoaVysMxQ_&Key-Pair-Id=PK123456789754'
41
- )
42
- end
43
-
44
- should "generate custom policy 2 correctly" do
45
- assert_equal(
46
- @cf_signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz', :policy_file => File.join(File.dirname(__FILE__), 'fixtures', 'custom_policy2')),
47
- 'http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz?Policy=eyAKICAgIlN0YXRlbWVudCI6IFt7IAogICAgICAiUmVzb3VyY2UiOiJodHRwOi8vKiIsIAogICAgICAiQ29uZGl0aW9uIjp7IAogICAgICAgICAiSXBBZGRyZXNzIjp7IkFXUzpTb3VyY2VJcCI6IjIxNi45OC4zNS4xLzMyIn0sCiAgICAgICAgICJEYXRlR3JlYXRlclRoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI0MTA3Mzc5MH0sCiAgICAgICAgICJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI1NTY3NDcxNn0KICAgICAgfSAKICAgfV0gCn0K&Signature=rc~5Qbbm8EJXjUTQ6Cn0LAxR72g1DOPrTmdtfbWVVgQNw0q~KHUAmBa2Zv1Wjj8dDET4XSL~Myh44CLQdu4dOH~N9huH7QfPSR~O4tIOS1WWcP~2JmtVPoQyLlEc8YHRCuN3nVNZJ0m4EZcXXNAS-0x6Zco2SYx~hywTRxWR~5Q_&Key-Pair-Id=PK123456789754'
48
- )
49
- end
50
- end
51
-
52
- context "Custom Policy Generation" do
53
- should "correctly generate custom policy" do
54
- starting = Time.now
55
- ending = Time.now + 3600
56
- ip_range = '216.98.35.1/32'
57
- assert_equal(
58
- @cf_signer.generate_custom_policy('http://d84l721fxaaqy9.cloudfront.net/downloads/*', :starting => starting, :ending => ending, :ip_range => ip_range),
59
- %({"Statement":[{"Resource":"http://d84l721fxaaqy9.cloudfront.net/downloads/*","Condition":{"DateLessThan":{"AWS:EpochTime":#{ending.to_i}},"DateGreaterThan":{"AWS:EpochTime":#{starting.to_i}},"IpAddress":{"AWS:SourceIp":"#{ip_range}"}}}]})
60
- )
61
- end
62
-
63
- end
64
-
65
- end
66
- end