aws-sdk 2.0.1 → 2.0.5

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.
Files changed (251) hide show
  1. package/.eslintrc +20 -0
  2. package/.gitignore +10 -0
  3. package/.travis.yml +20 -0
  4. package/.yardopts +20 -0
  5. package/.yardopts_guide +21 -0
  6. package/Gemfile +16 -0
  7. package/Gemfile.lock +34 -0
  8. package/README.md +5 -6
  9. package/Rakefile +14 -0
  10. package/UPGRADING.md +9 -4
  11. package/configuration.sample +5 -0
  12. package/dist/BUNDLE_LICENSE.txt +96 -0
  13. package/dist/aws-sdk.js +9594 -0
  14. package/dist/aws-sdk.min.js +21 -0
  15. package/dist-tools/.eslintrc +10 -0
  16. package/dist-tools/browser-builder.js +142 -0
  17. package/dist-tools/strategies/cache.js +68 -0
  18. package/dist-tools/strategies/default.js +165 -0
  19. package/dist-tools/test/browser-builder.mocha.spec.coffee +182 -0
  20. package/dist-tools/test/helpers.coffee +16 -0
  21. package/doc-src/guide/browser-building.md +93 -0
  22. package/doc-src/guide/browser-configuring-wif.md +287 -0
  23. package/doc-src/guide/browser-configuring.md +218 -0
  24. package/doc-src/guide/browser-examples.md +220 -0
  25. package/doc-src/guide/browser-intro.md +46 -0
  26. package/doc-src/guide/browser-making-requests.md +279 -0
  27. package/doc-src/guide/browser-services.md +75 -0
  28. package/doc-src/guide/index.md +41 -0
  29. package/doc-src/guide/node-configuring.md +272 -0
  30. package/doc-src/guide/node-examples.md +341 -0
  31. package/doc-src/guide/node-intro.md +32 -0
  32. package/doc-src/guide/node-making-requests.md +309 -0
  33. package/doc-src/guide/node-services.md +159 -0
  34. package/doc-src/templates/api-versions/model_documentor.rb +366 -0
  35. package/doc-src/templates/api-versions/plugin.rb +230 -0
  36. package/doc-src/templates/api-versions/templates/default/class/html/setup.rb +9 -0
  37. package/doc-src/templates/api-versions/templates/default/class/html/waiter_details_list.erb +7 -0
  38. package/doc-src/templates/api-versions/templates/default/class/html/waiter_summary.erb +7 -0
  39. package/doc-src/templates/api-versions/templates/default/docstring/html/experimental.erb +4 -0
  40. package/doc-src/templates/api-versions/templates/default/docstring/setup.rb +9 -0
  41. package/doc-src/templates/api-versions/templates/default/fulldoc/html/css/common.css +6 -0
  42. package/doc-src/templates/api-versions/templates/default/fulldoc/html/setup.rb +62 -0
  43. package/doc-src/templates/api-versions/templates/default/layout/html/services.erb +10 -0
  44. package/doc-src/templates/api-versions/templates/default/layout/html/setup.rb +28 -0
  45. package/doc-src/templates/api-versions/templates/default/module/html/box_info.erb +45 -0
  46. package/doc-src/templates/api-versions/templates/default/module/html/children.erb +8 -0
  47. package/doc-src/templates/api-versions/templates/default/tags/setup.rb +3 -0
  48. package/doc-src/templates/api-versions/templates/default/waiter_details/html/method_signature.erb +3 -0
  49. package/doc-src/templates/api-versions/templates/default/waiter_details/html/setup.rb +5 -0
  50. package/doc-src/templates/default/layout/html/footer.erb +31 -0
  51. package/doc-src/templates/default/layout/html/layout.erb +23 -0
  52. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/css/highlight.github.css +127 -0
  53. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/css/style.css +1192 -0
  54. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/img/logo.png +0 -0
  55. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/app.js +33 -0
  56. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/highlight.pack.js +27 -0
  57. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/AUTHORS +55 -0
  58. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/LICENSE +25 -0
  59. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js +247 -0
  60. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/file.png +0 -0
  61. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/searchtools.js +568 -0
  62. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/underscore.js +23 -0
  63. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/search.erb +29 -0
  64. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/search_index.erb +1 -0
  65. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/setup.rb +75 -0
  66. package/doc-src/templates/flasky_sphinx_guide/layout/html/layout.erb +93 -0
  67. package/doc-src/templates/flasky_sphinx_guide/layout/html/setup.rb +9 -0
  68. package/doc-src/templates/flasky_sphinx_guide/layout/html/sidebar.erb +45 -0
  69. package/doc-src/templates/flasky_sphinx_guide/onefile/html/layout.erb +51 -0
  70. package/doc-src/templates/flasky_sphinx_guide/onefile/html/setup.rb +1 -0
  71. package/eslint-rules/no-require-in-service.js +10 -0
  72. package/features/autoscaling/autoscaling.feature +21 -0
  73. package/features/autoscaling/step_definitions/autoscaling.js +49 -0
  74. package/features/cloudformation/cloudformation.feature +22 -0
  75. package/features/cloudformation/step_definitions/cloudformation.js +26 -0
  76. package/features/cloudfront/cloudfront.feature +28 -0
  77. package/features/cloudfront/step_definitions/cloudfront-latest.js +54 -0
  78. package/features/cloudfront/step_definitions/cloudfront.js +21 -0
  79. package/features/cloudsearch/cloudsearch.feature +34 -0
  80. package/features/cloudsearch/step_definitions/cloudsearch.js +42 -0
  81. package/features/cloudtrail/cloudtrail.feature +17 -0
  82. package/features/cloudtrail/step_definitions/cloudtrail.js +14 -0
  83. package/features/cloudwatch/cloudwatch.feature +15 -0
  84. package/features/cloudwatch/step_definitions/cloudwatch.js +48 -0
  85. package/features/datapipeline/datapipeline.feature +23 -0
  86. package/features/datapipeline/step_definitions/datapipeline.js +79 -0
  87. package/features/directconnect/directconnect.feature +20 -0
  88. package/features/directconnect/step_definitions/directconnect.js +44 -0
  89. package/features/dynamodb/crc32.feature +18 -0
  90. package/features/dynamodb/step_definitions/dynamodb.js +154 -0
  91. package/features/dynamodb/tables.feature +50 -0
  92. package/features/ec2/ec2.feature +28 -0
  93. package/features/ec2/step_definitions/ec2.js +65 -0
  94. package/features/elasticache/elasticache.feature +20 -0
  95. package/features/elasticache/step_definitions/elasticache.js +34 -0
  96. package/features/elasticbeanstalk/elasticbeanstalk.feature +22 -0
  97. package/features/elasticbeanstalk/step_definitions/elasticbeanstalk.js +38 -0
  98. package/features/elastictranscoder/elastictranscoder.feature +24 -0
  99. package/features/elastictranscoder/step_definitions/elastictranscoder.js +56 -0
  100. package/features/elb/elb.feature +19 -0
  101. package/features/elb/step_definitions/elb.js +37 -0
  102. package/features/emr/emr.feature +16 -0
  103. package/features/emr/step_definitions/emr.js +45 -0
  104. package/features/extra/assertions.js +29 -0
  105. package/features/extra/dummy.feature +0 -0
  106. package/features/extra/fixtures/testfile.txt +1 -0
  107. package/features/extra/helpers.js +113 -0
  108. package/features/extra/hooks.js +107 -0
  109. package/features/extra/world.js +12 -0
  110. package/features/glacier/glacier.feature +47 -0
  111. package/features/glacier/step_definitions/glacier.js +112 -0
  112. package/features/iam/iam.feature +24 -0
  113. package/features/iam/step_definitions/iam.js +66 -0
  114. package/features/importexport/importexport.feature +53 -0
  115. package/features/importexport/step_definitions/importexport.js +42 -0
  116. package/features/kinesis/kinesis.feature +9 -0
  117. package/features/kinesis/step_definitions/kinesis.js +10 -0
  118. package/features/opsworks/opsworks.feature +26 -0
  119. package/features/opsworks/step_definitions/opsworks.js +42 -0
  120. package/features/rds/rds.feature +32 -0
  121. package/features/rds/step_definitions/rds.js +72 -0
  122. package/features/redshift/redshift.feature +20 -0
  123. package/features/redshift/step_definitions/redshift.js +33 -0
  124. package/features/route53/route53.feature +41 -0
  125. package/features/route53/step_definitions/route53.js +97 -0
  126. package/features/s3/buckets.feature +40 -0
  127. package/features/s3/objects.feature +122 -0
  128. package/features/s3/step_definitions/buckets.js +136 -0
  129. package/features/s3/step_definitions/hooks.js +39 -0
  130. package/features/s3/step_definitions/objects.js +204 -0
  131. package/features/s3/step_definitions/proxy.js +44 -0
  132. package/features/ses/ses.feature +20 -0
  133. package/features/ses/step_definitions/ses.js +22 -0
  134. package/features/simpledb/simpledb.feature +29 -0
  135. package/features/simpledb/step_definitions/simpledb.js +46 -0
  136. package/features/sns/sns.feature +15 -0
  137. package/features/sns/step_definitions/sns.js +33 -0
  138. package/features/sqs/messages.feature +21 -0
  139. package/features/sqs/queues.feature +18 -0
  140. package/features/sqs/step_definitions/messages.js +46 -0
  141. package/features/sqs/step_definitions/queues.js +33 -0
  142. package/features/sqs/step_definitions/sqs.js +7 -0
  143. package/features/storagegateway/step_definitions/storagegateway.js +16 -0
  144. package/features/storagegateway/storagegateway.feature +13 -0
  145. package/features/sts/step_definitions/sts.js +35 -0
  146. package/features/sts/sts.feature +29 -0
  147. package/features/support/step_definitions/support.js +35 -0
  148. package/features/support/support.feature +18 -0
  149. package/features/swf/step_definitions/swf.js +38 -0
  150. package/features/swf/swf.feature +15 -0
  151. package/index.js +2 -0
  152. package/lib/core.js +2 -2
  153. package/lib/credentials/shared_ini_file_credentials.js +0 -1
  154. package/lib/event_listeners.js +13 -1
  155. package/lib/http/node.js +19 -30
  156. package/lib/model/resource_waiter.js +0 -4
  157. package/lib/model/shape.js +2 -1
  158. package/lib/protocol/rest_xml.js +1 -1
  159. package/lib/region_config.js +31 -0
  160. package/lib/region_config.json +56 -0
  161. package/lib/request.js +37 -45
  162. package/lib/sequential_executor.js +17 -34
  163. package/lib/service.js +17 -44
  164. package/lib/services/cloudsearchdomain.js +69 -0
  165. package/lib/services/route53.js +0 -12
  166. package/lib/services/s3.js +3 -19
  167. package/lib/signers/v4.js +2 -1
  168. package/lib/util.js +28 -3
  169. package/package.json +3 -3
  170. package/scripts/console +11 -3
  171. package/scripts/coverage +126 -0
  172. package/tasks/apis.rake +122 -0
  173. package/tasks/browser.rake +89 -0
  174. package/tasks/docs.rake +36 -0
  175. package/tasks/lib/cucumber_generator.rb +40 -0
  176. package/tasks/util.rake +33 -0
  177. package/test/browser/js/jasmine-1.3.1.js +2600 -0
  178. package/test/browser/js/jasmine-html.js +681 -0
  179. package/test/browser/runner.html +109 -0
  180. package/test/browser/runner.js +92 -0
  181. package/test/browser/sample/appinfo.sample.js +15 -0
  182. package/test/browser/sample/console.html +429 -0
  183. package/test/browser/sample/css/smoothness/images/animated-overlay.gif +0 -0
  184. package/test/browser/sample/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  185. package/test/browser/sample/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  186. package/test/browser/sample/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  187. package/test/browser/sample/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  188. package/test/browser/sample/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  189. package/test/browser/sample/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  190. package/test/browser/sample/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  191. package/test/browser/sample/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  192. package/test/browser/sample/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  193. package/test/browser/sample/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  194. package/test/browser/sample/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  195. package/test/browser/sample/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  196. package/test/browser/sample/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  197. package/test/browser/sample/css/smoothness/jquery-ui-1.10.1.custom.css +1175 -0
  198. package/test/browser/sample/css/smoothness/jquery-ui-1.10.1.custom.min.css +5 -0
  199. package/test/browser/sample/img/loading.gif +0 -0
  200. package/test/browser/sample/js/jquery-1.9.1.js +9597 -0
  201. package/test/browser/sample/js/jquery-ui-1.10.1.custom.js +14903 -0
  202. package/test/browser/sample/js/jquery-ui-1.10.1.custom.min.js +6 -0
  203. package/test/browser/sample/s3upload.html +111 -0
  204. package/test/browser.spec.coffee +207 -0
  205. package/test/config.spec.coffee +202 -0
  206. package/test/credential_provider_chain.spec.coffee +90 -0
  207. package/test/credentials.spec.coffee +452 -0
  208. package/test/endpoint.spec.coffee +80 -0
  209. package/test/event_listeners.spec.coffee +493 -0
  210. package/test/helpers.coffee +150 -0
  211. package/test/http_request.spec.coffee +55 -0
  212. package/test/json/builder.spec.coffee +129 -0
  213. package/test/json/parser.spec.coffee +108 -0
  214. package/test/metadata_service.spec.coffee +54 -0
  215. package/test/model/api.spec.coffee +67 -0
  216. package/test/model/shape.spec.coffee +23 -0
  217. package/test/node_http_client.spec.coffee +40 -0
  218. package/test/param_validator.spec.coffee +456 -0
  219. package/test/protocol/json.spec.coffee +167 -0
  220. package/test/protocol/query.spec.coffee +191 -0
  221. package/test/protocol/rest.spec.coffee +237 -0
  222. package/test/protocol/rest_json.spec.coffee +255 -0
  223. package/test/protocol/rest_xml.spec.coffee +329 -0
  224. package/test/query/query_param_serializer.spec.coffee +327 -0
  225. package/test/region_config.spec.coffee +50 -0
  226. package/test/request.spec.coffee +316 -0
  227. package/test/resource_waiter.spec.coffee +89 -0
  228. package/test/response.spec.coffee +81 -0
  229. package/test/sequential_executor.spec.coffee +118 -0
  230. package/test/service.spec.coffee +230 -0
  231. package/test/services/cloudfront.spec.coffee +44 -0
  232. package/test/services/cloudsearchdomain.spec.coffee +23 -0
  233. package/test/services/dynamodb.spec.coffee +32 -0
  234. package/test/services/ec2.spec.coffee +78 -0
  235. package/test/services/elastictranscoder.spec.coffee +43 -0
  236. package/test/services/glacier.spec.coffee +61 -0
  237. package/test/services/rds.spec.coffee +38 -0
  238. package/test/services/route53.spec.coffee +77 -0
  239. package/test/services/s3.spec.coffee +538 -0
  240. package/test/services/simpledb.spec.coffee +12 -0
  241. package/test/services/sqs.spec.coffee +130 -0
  242. package/test/services/sts.spec.coffee +72 -0
  243. package/test/services/swf.spec.coffee +6 -0
  244. package/test/signers/presign.spec.coffee +36 -0
  245. package/test/signers/s3.spec.coffee +297 -0
  246. package/test/signers/v2.spec.coffee +68 -0
  247. package/test/signers/v4.spec.coffee +135 -0
  248. package/test/util.spec.coffee +510 -0
  249. package/test/xml/builder.spec.coffee +529 -0
  250. package/test/xml/parser.spec.coffee +587 -0
  251. package/lib/services/simpledb.js +0 -15
@@ -0,0 +1,510 @@
1
+ AWS = require('./helpers').AWS
2
+ Buffer = AWS.util.Buffer
3
+
4
+ describe 'uriEscape', ->
5
+
6
+ e = AWS.util.uriEscape
7
+
8
+ it 'escapes spaces as %20', ->
9
+ expect(e('a b')).toEqual('a%20b')
10
+
11
+ it 'escapes + as %2B', ->
12
+ expect(e('a+b')).toEqual('a%2Bb')
13
+
14
+ it 'escapes / as %2F', ->
15
+ expect(e('a/b')).toEqual('a%2Fb')
16
+
17
+ it 'escapes \' as %27', ->
18
+ expect(e('a\'b')).toEqual('a%27b')
19
+
20
+ it 'escapes * as %2A', ->
21
+ expect(e('a*b')).toEqual('a%2Ab')
22
+
23
+ it 'does not escape ~', ->
24
+ expect(e('a~b')).toEqual('a~b')
25
+
26
+ it 'encodes utf8 characters', ->
27
+ expect(e('ёŝ')).toEqual('%D1%91%C5%9D')
28
+
29
+ describe 'uriEscapePath', ->
30
+
31
+ e = AWS.util.uriEscapePath
32
+
33
+ it 'does not escape forward slashes', ->
34
+ s = 'a&b/x=y/1+2/m?n'
35
+ expect(e(s)).toEqual('a%26b/x%3Dy/1%2B2/m%3Fn')
36
+
37
+ it 'leaves leading and trailing forward slashes in place', ->
38
+ s = '/ab cd/'
39
+ expect(e(s)).toEqual('/ab%20cd/')
40
+
41
+ describe 'AWS.util.queryParamsToString', ->
42
+ qpts = AWS.util.queryParamsToString
43
+
44
+ it 'sorts query parameters before stringifying', ->
45
+ expect(qpts(c: '1', b: '2', a: '3')).toEqual('a=3&b=2&c=1')
46
+
47
+ it 'handles empty values', ->
48
+ expect(qpts(a: '', b: '2')).toEqual('a=&b=2')
49
+
50
+ it 'handles null/undefined values', ->
51
+ expect(qpts(a: undefined, b: null)).toEqual('a&b')
52
+
53
+ it 'calls uriEscape on each name and value', ->
54
+ spy = spyOn(AWS.util, 'uriEscape').andCallThrough()
55
+ qpts(c: '1', b: '2', a: '3')
56
+ expect(spy.calls.length).toEqual(6)
57
+
58
+ it 'handles values as lists', ->
59
+ expect(qpts(a: ['1', '2', '3'], b: '4')).toEqual('a=1&a=2&a=3&b=4')
60
+
61
+ it 'escapes list values', ->
62
+ expect(qpts(a: ['+', '&', '*'], b: '4')).toEqual('a=%26&a=%2A&a=%2B&b=4')
63
+
64
+ it 'does not provide value if value is null', ->
65
+ expect(qpts(a: null, b: null)).toEqual('a&b')
66
+
67
+ describe 'AWS.util.date', ->
68
+
69
+ util = AWS.util.date
70
+
71
+ describe 'getDate', ->
72
+ it 'should return current date by default', ->
73
+ oldDate = Date; now = {}
74
+ mock = jasmine.createSpy().andReturn(now)
75
+ `typeof window !== 'undefined' ? (window.Date = mock) : (Date = mock);`
76
+ expect(util.getDate()).toBe(now)
77
+ `typeof window !== 'undefined' ? (window.Date = oldDate) : (Date = oldDate);`
78
+
79
+ describe 'iso8601', ->
80
+ it 'should return date formatted as YYYYMMDDTHHnnssZ', ->
81
+ date = new Date(600000); date.setMilliseconds(0)
82
+ spyOn(util, 'getDate').andCallFake -> date
83
+ expect(util.iso8601()).toEqual('1970-01-01T00:10:00.000Z')
84
+
85
+ it 'should allow date parameter', ->
86
+ date = new Date(660000); date.setMilliseconds(0)
87
+ expect(util.iso8601(date)).toEqual('1970-01-01T00:11:00.000Z')
88
+
89
+ describe 'rfc822', ->
90
+ it 'should return date formatted as YYYYMMDDTHHnnssZ', ->
91
+ date = new Date(600000); date.setMilliseconds(0)
92
+ spyOn(util, 'getDate').andCallFake -> date
93
+ expect(util.rfc822()).toMatch(/^Thu, 0?1 Jan 1970 00:10:00 (GMT|UTC)$/)
94
+
95
+ it 'should allow date parameter', ->
96
+ date = new Date(660000); date.setMilliseconds(0)
97
+ expect(util.rfc822(date)).toMatch(/^Thu, 0?1 Jan 1970 00:11:00 (GMT|UTC)$/)
98
+
99
+ describe 'unixTimestamp', ->
100
+ it 'should return date formatted as unix timestamp', ->
101
+ date = new Date(600000); date.setMilliseconds(0)
102
+ spyOn(util, 'getDate').andCallFake -> date
103
+ expect(util.unixTimestamp()).toEqual(600)
104
+
105
+ it 'should allow date parameter', ->
106
+ date = new Date(660000); date.setMilliseconds(0)
107
+ expect(util.unixTimestamp(date)).toEqual(660)
108
+
109
+ it 'should return date formatted as unix timestamp with milliseconds', ->
110
+ spyOn(util, 'getDate').andCallFake -> new Date(600123)
111
+ expect(util.unixTimestamp()).toEqual(600.123)
112
+
113
+ describe 'AWS.util.string', ->
114
+ len = AWS.util.string.byteLength
115
+
116
+ describe 'byteLength', ->
117
+ it 'handles null/undefined objects', ->
118
+ expect(len(undefined)).toEqual(0)
119
+ expect(len(null)).toEqual(0)
120
+
121
+ it 'handles buffer input', ->
122
+ expect(len(new Buffer('∂ƒ©∆'))).toEqual(10)
123
+
124
+ it 'handles string input', ->
125
+ expect(len('')).toEqual(0)
126
+ expect(len('∂ƒ©∆')).toEqual(10)
127
+
128
+ if AWS.util.isNode()
129
+ it 'handles file object input (path property)', ->
130
+ fs = require('fs')
131
+ file = fs.createReadStream(__filename)
132
+ fileLen = fs.lstatSync(file.path).size
133
+ expect(len(file)).toEqual(fileLen)
134
+ expect(len(path: __filename)).toEqual(fileLen)
135
+
136
+ it 'fails if input is not a string, buffer, or file', ->
137
+ err = null
138
+ try
139
+ len(3.14)
140
+ catch e
141
+ err = e
142
+
143
+ expect(err.message).toEqual('Cannot determine length of 3.14')
144
+ expect(err.object).toBe(3.14)
145
+
146
+ it 'ignores path property unless it is a string', ->
147
+ object = {}
148
+ err = null
149
+ try
150
+ len(object)
151
+ catch e
152
+ err = e
153
+
154
+ expect(err.message).toMatch(/Cannot determine length of /)
155
+ expect(err.object).toBe(object)
156
+
157
+ describe 'AWS.util.ini', ->
158
+ describe 'parse', ->
159
+ it 'parses an ini file', ->
160
+ ini = '''
161
+ ; comment at the beginning of the line
162
+ [section1] ; comment at end of line
163
+ invalidline
164
+ key1=value1 ; another comment
165
+ key2 = value2;value3
166
+ [emptysection]
167
+ '''
168
+ map = AWS.util.ini.parse(ini)
169
+ expect(map.section1.key1).toEqual('value1')
170
+ expect(map.section1.key2).toEqual('value2;value3')
171
+ expect(map.emptysection).toBe(undefined)
172
+
173
+ describe 'AWS.util.buffer', ->
174
+ describe 'concat', ->
175
+ it 'concatenates a list of buffers', ->
176
+ buffer1 = new Buffer('abcdefg')
177
+ buffer2 = new Buffer('hijklmn')
178
+ buffer3 = AWS.util.buffer.concat([buffer1, buffer2])
179
+ expect(buffer3.length).toEqual(14)
180
+ expect(buffer3.toString()).toEqual('abcdefghijklmn')
181
+
182
+ describe 'AWS.util.crypto', ->
183
+
184
+ util = AWS.util.crypto
185
+
186
+ describe 'crc32', ->
187
+ it 'returns the correct CRC32 value for binary data', ->
188
+ buffer = new Buffer(4433);
189
+ for i in [0...buffer.length]
190
+ buffer.writeUInt8 i % 256, i
191
+ expect(util.crc32(buffer)).toEqual(899332870)
192
+
193
+ it 'handles String values', ->
194
+ string = '{"ConsumedCapacityUnits":1.0}'
195
+ expect(util.crc32(string)).toEqual(2614884069)
196
+
197
+ describe 'toHex', ->
198
+ it 'should convert binary data to hex string', ->
199
+ expect(util.toHex('ABC')).toEqual('414243')
200
+
201
+ describe 'hmac', ->
202
+ input = 'foo'
203
+ key = 'KEY'
204
+ result = '116a3725a3540067a09e4dba64bb6b3fb27b4d98a1a2e2dbcb8b4cffa73585d5'
205
+
206
+ it 'should return a keyed hash as a binary digest', ->
207
+ expected = util.hmac(key, input)
208
+ expect(util.toHex(expected)).toEqual(result)
209
+
210
+ it 'should return a keyed hash as hex digest', ->
211
+ expected = util.hmac(key, input, 'hex')
212
+ expect(expected).toEqual(result)
213
+
214
+ it 'accepts the crypto function as an argument', ->
215
+ r = util.hmac('secret', 'the quick brown fox', 'base64', 'sha1')
216
+ expect(r).toEqual('z1BzGT+uG/2qGzE1UHb5m/skn1E=')
217
+
218
+ it 'accepts UTF-8 input for string', ->
219
+ r = util.hmac('foo', 'å∆ç∂', 'hex')
220
+ expect(r).toEqual('bc11556145cbe4935ba187b9f8ba0c12bae2c866e5795013dfe2d08cabc33e13')
221
+
222
+ describe 'sha256', ->
223
+ input = 'foo'
224
+ result = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
225
+
226
+ it 'should return binary data hashed with sha256', ->
227
+ expected = util.sha256(input)
228
+ expect(util.toHex(expected)).toEqual(result)
229
+
230
+ it 'should return hex data hashed with sha256', ->
231
+ expected = util.sha256(input, 'hex')
232
+ expect(expected).toEqual(result)
233
+
234
+ it 'accepts UTF-8 input', ->
235
+ r = util.sha256('ß∂ƒ©', 'hex')
236
+ expect(r).toEqual('3c01ddd413d2cacac59a255e4aade0d9058a8a9ea8b2dfe5bb2dc4ed132b4139')
237
+
238
+ describe 'md5', ->
239
+ input = 'foo'
240
+ result = 'acbd18db4cc2f85cedef654fccc4a4d8'
241
+
242
+ it 'should return binary data hashed with md5', ->
243
+ expected = util.md5(input)
244
+ expect(util.toHex(expected)).toEqual(result)
245
+
246
+ it 'should return hex data hashed with md5', ->
247
+ expected = util.md5(input, 'hex')
248
+ expect(expected).toEqual(result)
249
+
250
+ it 'accepts UTF-8 input', ->
251
+ r = util.md5('ᅢ', 'hex')
252
+ expect(r).toEqual('b497dbbe19fb58cddaeef11f9d40804c')
253
+
254
+ describe 'AWS.util.each', ->
255
+ it 'should iterate over a hash', ->
256
+ parts = []
257
+ AWS.util.each {a: 1, b: 2, c: 3}, (key, item) ->
258
+ parts.push([key + '_', item + 1])
259
+ expect(parts).toEqual([['a_', 2], ['b_', 3], ['c_', 4]])
260
+
261
+ it 'should iterate over an array', ->
262
+ total = 0
263
+ AWS.util.each [1, 2, 3], (idx, item) ->
264
+ total += item
265
+ expect(total).toEqual(6)
266
+
267
+ it 'should ignore inherited properties', ->
268
+ objCtor = -> this.a = 1; this.b = 2; this.c = 3
269
+ objCtor.prototype = d: 4, e: 5, f: 6
270
+ obj = new objCtor()
271
+ parts = []
272
+ AWS.util.each obj, (key, item) ->
273
+ parts.push([key + '_', item + 1])
274
+ expect(parts).toEqual([['a_', 2], ['b_', 3], ['c_', 4]])
275
+
276
+ it 'callback should not change "this" scope', ->
277
+ new ->
278
+ this.class = 'MyClass'
279
+ self = this
280
+ AWS.util.each.apply this, [[1, 2, 3], ->
281
+ expect(this).toBe(self)]
282
+
283
+ it 'can abort out of loop', ->
284
+ string = ''
285
+ AWS.util.each {a: 1, b: 2, c: 3}, (key, item) ->
286
+ return AWS.util.abort if item == 2
287
+ string += key
288
+
289
+ expect(string).toEqual('a')
290
+
291
+ describe 'AWS.util.arrayEach', ->
292
+ it 'should iterate over arrays', ->
293
+ total = 0
294
+ AWS.util.arrayEach [1, 2, 3], (item) ->
295
+ total += item
296
+ expect(total).toEqual(6)
297
+
298
+ it 'should pass index as second parameter', ->
299
+ lastIndex = null
300
+ AWS.util.arrayEach [1, 2, 3], (item, idx) ->
301
+ expect(typeof(idx)).toEqual('number')
302
+ expect(lastIndex).toEqual(idx - 1) if lastIndex != null
303
+ lastIndex = idx
304
+
305
+ it 'can abort out of loop', ->
306
+ total = 0
307
+ AWS.util.arrayEach [1, 2, 3], (item, idx) ->
308
+ return AWS.util.abort if idx == 1
309
+ total += item
310
+
311
+ expect(total).toEqual(1)
312
+
313
+ describe 'AWS.util.copy', ->
314
+ it 'does not copy null or undefined', ->
315
+ expect(AWS.util.copy(null)).toEqual(null)
316
+ expect(AWS.util.copy(undefined)).toEqual(undefined)
317
+
318
+ it 'should perform a shallow copy of an object', ->
319
+ obj = a: 1, b: 2, c: 3
320
+ copied = AWS.util.copy(obj)
321
+ expect(copied).not.toBe(obj)
322
+ expect(copied).toEqual(a: 1, b: 2, c: 3)
323
+
324
+ it 'should copy inherited properties', ->
325
+ objCtor = -> this.a = 1; this.b = 2; this.c = 3
326
+ objCtor.prototype = d: 4
327
+ obj = new objCtor()
328
+ copied = AWS.util.copy(obj)
329
+ expect(copied).not.toBe(obj)
330
+ expect(copied).toEqual(a: 1, b: 2, c: 3, d: 4)
331
+
332
+ describe 'AWS.util.merge', ->
333
+ it 'should merge an object into another and return new object', ->
334
+ obj = a: 1, b: 2, c: 3
335
+ newObj = AWS.util.merge(obj, {d: 4, e: 5, a: 6})
336
+ expect(newObj).toEqual(a: 6, b: 2, c: 3, d: 4, e: 5)
337
+ expect(obj).toEqual(a: 1, b: 2, c: 3)
338
+
339
+ describe 'AWS.util.update', ->
340
+ it 'should merge an object into another', ->
341
+ obj = a: 1, b: 2, c: 3
342
+ AWS.util.update(obj, {d: 4, e: 5, a: 6})
343
+ expect(obj).toEqual(a: 6, b: 2, c: 3, d: 4, e: 5)
344
+
345
+ it 'should return the merged object', ->
346
+ obj = a: 1, b: 2
347
+ expect(AWS.util.update(obj, c: 3)).toBe(obj)
348
+
349
+ describe 'AWS.util.inherit', ->
350
+ it 'should inherit an object and append features', ->
351
+ Base = (value) ->
352
+ this.defaultValue = value
353
+
354
+ Base.prototype =
355
+ main: -> 'main'
356
+ other: 'other'
357
+
358
+ Derived = AWS.util.inherit Base,
359
+ constructor: (value) ->
360
+ Base.apply(this, [value + 5])
361
+
362
+ main: -> 'notMain'
363
+ foo: -> 'bar'
364
+
365
+ derived = new Derived(5)
366
+ expect(derived instanceof Base).toBeTruthy()
367
+ expect(derived.constructor).toBe(Derived)
368
+ expect(derived.main()).toEqual('notMain')
369
+ expect(derived.other).toEqual('other')
370
+ expect(derived.defaultValue).toEqual(10)
371
+ expect(derived.foo()).toEqual('bar')
372
+
373
+ it 'should create pass-through constructor if not defined', ->
374
+ Base = AWS.util.inherit
375
+ constructor: jasmine.createSpy()
376
+
377
+ Derived = AWS.util.inherit Base,
378
+ other: true
379
+
380
+ derived = new Derived(1, 2, 'three')
381
+ expect(derived.other).toEqual(true)
382
+ expect(Base.prototype.constructor).toHaveBeenCalledWith(1, 2, 'three')
383
+
384
+ describe 'AWS.util.mixin', ->
385
+ it 'copies properties to other object prototype', ->
386
+ obj = prototype: a: 1, b: 2
387
+ AWS.util.mixin(obj, prototype: b: 3, c: 4)
388
+ expect(obj.prototype).toEqual(a: 1, b: 3, c: 4)
389
+
390
+ it 'resets prototype constructor', ->
391
+ obj = prototype: constructor: 'PASS'
392
+ AWS.util.mixin(obj, prototype: constructor: 'FAIL')
393
+ expect(obj.prototype).toEqual(constructor: 'PASS')
394
+
395
+ it 'returns original klass', ->
396
+ obj = prototype: foo: 1
397
+ out = AWS.util.mixin(obj, prototype: bar: 2)
398
+ expect(out).toBe(obj)
399
+
400
+ describe 'AWS.util.isType', ->
401
+ it 'accepts function for type', ->
402
+ expect(AWS.util.isType([], Array)).toEqual(true)
403
+
404
+ it 'accepts string for type', ->
405
+ expect(AWS.util.isType([], 'Array')).toEqual(true)
406
+
407
+ describe 'AWS.util.isEmpty', ->
408
+
409
+ it 'returns true when passed an empty object literal', ->
410
+ expect(AWS.util.isEmpty({})).toEqual(true)
411
+
412
+ it 'returns true when passed a non-empty object literal', ->
413
+ expect(AWS.util.isEmpty({a:1})).toEqual(false)
414
+
415
+ describe 'AWS.util.error', ->
416
+ it 'returns the created error object with extra options', ->
417
+ origError = new Error()
418
+ err = AWS.util.error(origError, message: 'msg', code: 'code')
419
+ expect(err).toBe(origError)
420
+ expect(err.message).toEqual('msg')
421
+ expect(err.code).toEqual('code')
422
+
423
+ it 'accepts missing options', ->
424
+ origError = new Error('ERROR')
425
+ err = AWS.util.error(origError)
426
+ expect(err).toBe(origError)
427
+ expect(err.message).toEqual('ERROR')
428
+
429
+ it 'maintains the original error message property', ->
430
+ origError = new Error('ERROR')
431
+ err = AWS.util.error(origError, {code: 'code'})
432
+ expect(err).toBe(origError)
433
+ expect(err.message).toEqual('ERROR')
434
+ expect(err.code).toEqual('code')
435
+
436
+ it 'keeps track of the old error', ->
437
+ origError = new Error('ERROR')
438
+ origError.value = 1
439
+ err = AWS.util.error(origError, code: 'code', message: 'FOO')
440
+ expect(err.originalError.message).toEqual('ERROR')
441
+ expect(err.originalError.code).toEqual(undefined)
442
+ expect(err.originalError.value).toEqual(1)
443
+
444
+ describe 'AWS.util.base64', ->
445
+
446
+ base64 = AWS.util.base64
447
+
448
+ describe 'encode', ->
449
+ it 'encodes the given string', ->
450
+ expect(base64.encode('foo')).toEqual('Zm9v')
451
+ expect(base64.encode('ёŝ')).toEqual('0ZHFnQ==')
452
+
453
+ describe 'decode', ->
454
+ it 'decodes the given string', ->
455
+ expect(base64.decode('Zm9v').toString()).toEqual('foo')
456
+ expect(base64.decode('0ZHFnQ==').toString()).toEqual('ёŝ')
457
+
458
+ describe 'AWS.util.jamespath', ->
459
+ query = AWS.util.jamespath.query
460
+ find = AWS.util.jamespath.find
461
+
462
+ describe 'query', ->
463
+ it 'can find a toplevel element of a data structure', ->
464
+ expect(query('foo', foo: 'value')).toEqual(['value'])
465
+
466
+ it 'can find a nested element of a data structure', ->
467
+ expect(query('foo.bar.baz', foo: bar: baz: 'value')).toEqual(['value'])
468
+
469
+ it 'can index an element (positive and negative indexes)', ->
470
+ data = foo: bar: [{baz: 'wrong'}, {baz: 'right'}, {baz: 'wrong'}]
471
+ expect(query('foo.bar[1].baz', data)).toEqual(['right'])
472
+ expect(query('foo.bar[-2].baz', data)).toEqual(['right'])
473
+
474
+ it 'can index an element with wildcard', ->
475
+ data = foo: bar: [{baz: 'wrong'}, {baz: 'right'}, {baz: 'wrong'}]
476
+ expect(query('foo.bar[*].baz', data)).toEqual(['wrong', 'right', 'wrong'])
477
+
478
+ it 'returns empty array if element is not found', ->
479
+ data = foo: notBar: baz: 'value'
480
+ expect(query('foo.bar.baz', data)).toEqual([])
481
+
482
+ it 'allows multiple expressions to be ORed', ->
483
+ data = foo: {key1: 'wrong'}, bar: {key2: 'right'}
484
+ expect(query('foo.key2 or bar.key2', data)).toEqual(['right'])
485
+
486
+ it 'returns multiple matches if a wildcard is used', ->
487
+ data = foo:
488
+ child1: bar: 'value1'
489
+ child2: bar: 'value2'
490
+ child3: bar: 'value3'
491
+ expect(query('foo.*.bar', data)).toEqual(['value1', 'value2', 'value3'])
492
+
493
+ it 'can support wildcard on both token and index', ->
494
+ data = foo:
495
+ child1: ['value1', 'value2']
496
+ child2: ['value3']
497
+ child4: 'notarray'
498
+ expect(query('foo.*[*]', data)).toEqual(['value1', 'value2', 'value3'])
499
+
500
+ it 'can support array flattening', ->
501
+ data = foo: [ {bar: 1}, {bar: 2}, {bar: 3} ]
502
+ expect(query('foo[].bar', data)).toEqual([1, 2, 3])
503
+
504
+
505
+ describe 'find', ->
506
+ it 'returns the first match of query', ->
507
+ expect(find('foo.*', foo: bar: 1, baz: 2)).toEqual(1)
508
+
509
+ it 'returns null if no match is found', ->
510
+ expect(find('invalid.*', foo: bar: 1, baz: 2)).toEqual(null)