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,456 @@
1
+ helpers = require('./helpers')
2
+ AWS = helpers.AWS
3
+ Buffer = AWS.util.Buffer
4
+
5
+ describe 'AWS.ParamValidator', ->
6
+ [members, input] = [{}, {}]
7
+
8
+ validate = (params) ->
9
+ r = input
10
+ if r && !r.xml && !r.payload
11
+ r = AWS.Model.Shape.create(input, {api: {}})
12
+ new AWS.ParamValidator().validate(r, params)
13
+
14
+ expectValid = (params) ->
15
+ expect(validate(params)).toEqual true
16
+
17
+ expectError = (message, params) ->
18
+ if params == undefined
19
+ [message, params] = [undefined, message]
20
+ expect(-> validate(params)).toThrow(message)
21
+
22
+ # empty input (nil or {}) means no arguments are accepted
23
+ describe 'empty input', ->
24
+ beforeEach ->
25
+ input = type: 'structure'
26
+
27
+ it 'accepts an empty hash when the input are an empty hash', ->
28
+ expectValid {}
29
+
30
+ it 'does not accept params in the given hash', ->
31
+ expectError foo: 'bar'
32
+
33
+ # Param (hash) keys can be given as strings or symbols, but
34
+ # are case sensitive.
35
+ describe 'param keys', ->
36
+ beforeEach ->
37
+ input =
38
+ members:
39
+ foo: {}, bar: type: 'string'
40
+
41
+ it 'accepts string keys', ->
42
+ expectValid foo: 'foo'
43
+ expectValid bar: 'bar'
44
+
45
+ it 'rejects keys that do not match case', ->
46
+ expectError Bar: 'bar'
47
+ expectError Foo: 'foo'
48
+
49
+ # Params not described in the input are not accepted.
50
+ describe 'unexpected params', ->
51
+ beforeEach ->
52
+ input =
53
+ members:
54
+ string1: {}
55
+ string2: {}
56
+ hash:
57
+ type: 'structure'
58
+ members:
59
+ good: {}
60
+
61
+ it 'throws an ArgumentError for un-described params', ->
62
+ expectError string3: 'xyz'
63
+
64
+ it 'rejects nested params that are not described in the input', ->
65
+ expectValid hash: good: 'abc'
66
+ expectError hash: bad: 'abc'
67
+
68
+ # Params that are hashes (structures) can specify that some or all
69
+ # of their nested params are required. When the parent param is
70
+ # present, the required nested params must also be present or an
71
+ # ArgumentError is raised. If the parent param is optional and not
72
+ # provided, then missing nested required params will not raise an error.
73
+ describe 'required params', ->
74
+ beforeEach ->
75
+ input =
76
+ required: ['req']
77
+ members:
78
+ req: type: 'string'
79
+ opt:
80
+ type: 'structure'
81
+ required: ['req']
82
+ members: req: type: 'string'
83
+
84
+ it 'throws an error if a top-level required param is omitted', ->
85
+ expectError {}
86
+
87
+ it 'throws an error if a top-level required param is null', ->
88
+ expectError req: null
89
+
90
+ it 'optional params can be omitted, even if they have required params', ->
91
+ expectValid req: 'abc'
92
+
93
+ it 'requires nested required params when the parent is present', ->
94
+ expectError req: 'abc', opt: {}
95
+
96
+ it 'accepts nested required params', ->
97
+ expectValid req: 'abc', opt: req: 'xyz'
98
+
99
+ it 'accepts empty strings in required params', ->
100
+ expectValid req: ''
101
+
102
+ it 'accepts 0 in required params', ->
103
+ input.members.req.type = 'integer'
104
+ expectValid req: 0
105
+
106
+ it 'accepts false in required params', ->
107
+ input.members.req.type = 'boolean'
108
+ expectValid req: false
109
+
110
+ # The root params is always a structure (hash) by default, but
111
+ # you can also nest structures.
112
+ describe 'structure', ->
113
+ beforeEach ->
114
+ input =
115
+ members:
116
+ hash1:
117
+ type: 'structure'
118
+ members:
119
+ param1: {}
120
+ param2: {}
121
+ hash2:
122
+ type: 'structure'
123
+ required: ['param4']
124
+ members:
125
+ param3: type: 'boolean'
126
+ param4: type: 'integer'
127
+
128
+ it 'accepts hashes', ->
129
+ expectValid hash1: {}
130
+
131
+ it 'accepts hashes with params', ->
132
+ expectValid hash1: param1: 'a', param2: 'b'
133
+
134
+ it 'throws an error for non hashes', ->
135
+ expectError hash1: 'oops'
136
+
137
+ it 'throws an error for unknown hash members', ->
138
+ expectError hash1: param3: 'c'
139
+
140
+ it 'allows nesting structures', ->
141
+ expectValid hash1: hash2: param3: true, param4: 123
142
+
143
+ it 'rejects unknown members', ->
144
+ expectError hash1: oops: 'abc'
145
+
146
+ it 'does not check inherited properties on parameters', ->
147
+ cls = -> this
148
+ cls.prototype.otherKey = 'value'
149
+ obj = new cls
150
+ obj.hash1 = {}
151
+ expectValid obj
152
+
153
+ describe 'list', ->
154
+ beforeEach ->
155
+ members = {}
156
+ input =
157
+ members:
158
+ array: type: 'list', member: members
159
+
160
+ it 'accepts an array for list params', ->
161
+ expectValid array: []
162
+
163
+ it 'throws an error if list params are not arrays', ->
164
+ expectError array: {}
165
+
166
+ it 'supports nested structures', ->
167
+ members.type = 'structure'
168
+ members.members = name: {}
169
+ expectValid array: [{name: 'abc'}, {name: 'mno'}, {name: 'xyz'}]
170
+ expectError array: [{badKey: 'abc'}]
171
+
172
+ describe 'map', ->
173
+ beforeEach ->
174
+ members = {}
175
+ input =
176
+ members:
177
+ hash: type: 'map', value: members
178
+
179
+ it 'accepts maps', ->
180
+ expectValid hash: {}
181
+
182
+ it 'accepts null', ->
183
+ expectValid hash: null
184
+
185
+ it 'rejects non-maps', ->
186
+ expectError hash: 'oops'
187
+
188
+ it 'accepts user-supplied maps keys', ->
189
+ expectValid hash: a: '1', b: '2', c: '3'
190
+
191
+ it 'supports nested params', ->
192
+ members.type = 'structure'
193
+ members.members =
194
+ param1: type: 'list', member: type: 'string'
195
+ param2: type: 'integer'
196
+ param3: type: 'structure', members: param4: {}
197
+
198
+ expectValid hash:
199
+ foo: param1: ['a', 'b', 'c']
200
+ bar: param2: 123
201
+ yuck: param3: param4: 'xyz'
202
+ expectError hash: foo: param4: 'abc'
203
+
204
+ describe 'boolean', ->
205
+ beforeEach ->
206
+ input = members: param: type: 'boolean'
207
+
208
+ it 'accepts true', ->
209
+ expectValid param: true
210
+
211
+ it 'accpets false', ->
212
+ expectValid param: false
213
+
214
+ it 'accepts null', ->
215
+ expectValid param: null
216
+
217
+ it 'rejects other values', ->
218
+ expectError param: 'true'
219
+
220
+ describe 'timestamp', ->
221
+ beforeEach ->
222
+ input = members: param: type: 'timestamp'
223
+
224
+ it 'accepts Date objects', ->
225
+ expectValid param: new Date()
226
+
227
+ it 'accepts strings formatted like datetimes', ->
228
+ expectValid param: '2012-01-02T10:11:12Z'
229
+ expectValid param: '2012-01-02T10:11:12.0001Z'
230
+
231
+ it 'accepts UNIX timestamps as number values', ->
232
+ expectValid param: 12345
233
+
234
+ it 'accepts null', ->
235
+ expectValid param: null
236
+
237
+ it 'rejects other param values', ->
238
+ expectError param: 'abc'
239
+
240
+ describe 'string', ->
241
+ beforeEach ->
242
+ input = members: param: type: 'string'
243
+
244
+ it 'accepts strings', ->
245
+ expectValid param: 'abc'
246
+
247
+ it 'accepts empty string', ->
248
+ expectValid param: ''
249
+
250
+ it 'accepts null', ->
251
+ expectValid param: null
252
+
253
+ it 'rejects other objects', ->
254
+ expectError param: 123
255
+ expectError param: {}
256
+ expectError param: []
257
+
258
+ describe 'float', ->
259
+ beforeEach ->
260
+ input = members: param: type: 'float'
261
+
262
+ it 'accepts floats', ->
263
+ expectValid param: 1.23
264
+
265
+ it 'accepts integers', ->
266
+ expectValid param: 123
267
+
268
+ it 'accepts floats formatted as strings', ->
269
+ expectValid param: '1.23'
270
+
271
+ it 'accepts null', ->
272
+ expectValid param: null
273
+
274
+ it 'rejects other objects', ->
275
+ expectError param: 'NOTFLOAT'
276
+
277
+ describe 'integer', ->
278
+ beforeEach ->
279
+ input = members: param: type: 'integer'
280
+
281
+ it 'accepts integers', ->
282
+ expectValid param: 123
283
+
284
+ it 'accepts integers formatted as strings', ->
285
+ expectValid param: '123'
286
+
287
+ it 'accepts null', ->
288
+ expectValid param: null
289
+
290
+ it 'rejects other objects', ->
291
+ expectError param: 'NOTINT'
292
+
293
+ describe 'base64', ->
294
+ beforeEach ->
295
+ input = members: param: type: 'base64'
296
+
297
+ it 'accepts strings', ->
298
+ expectValid param: 'abc'
299
+
300
+ it 'accepts Buffers', ->
301
+ expectValid param: new Buffer(100)
302
+
303
+ it 'accepts typed arrays', ->
304
+ expectValid param: new Uint8Array(1, 2, 3)
305
+ expectValid param: new Uint32Array(1, 2, 3)
306
+
307
+ it 'accepts null', ->
308
+ expectValid param: null
309
+
310
+ it 'rejects other objects', ->
311
+ expectError param: {}
312
+
313
+ if AWS.util.isBrowser()
314
+ it 'accepts Blob objects', ->
315
+ try blob = new Blob
316
+ if blob then expectValid param: blob
317
+
318
+ it 'accepts ArrayBuffer objects', ->
319
+ expectValid param: new ArrayBuffer
320
+
321
+ it 'accepts DataView objects', ->
322
+ expectValid param: new DataView(new ArrayBuffer)
323
+
324
+ describe 'binary', ->
325
+ beforeEach ->
326
+ input = members: param: type: 'binary'
327
+
328
+ it 'accepts strings', ->
329
+ expectValid param: 'abc'
330
+
331
+ it 'accepts Buffers', ->
332
+ expectValid param: new Buffer(100)
333
+
334
+ it 'accepts Streams', ->
335
+ Stream = require('stream').Stream
336
+ expectValid param: new Stream()
337
+
338
+ it 'accepts null', ->
339
+ expectValid param: null
340
+
341
+ it 'rejects other objects', ->
342
+ expectError param: {}
343
+
344
+ describe 'payloads', ->
345
+ it 'validates from payload key if input include an xml element', ->
346
+ input =
347
+ type: 'structure'
348
+ required: ['body']
349
+ payload: 'body'
350
+ members:
351
+ notbody: type: 'string'
352
+ body:
353
+ type: 'structure'
354
+ members: enabled: type: 'boolean'
355
+
356
+ expectValid body: { enabled: true }, notbody: 'true'
357
+
358
+ describe 'error messages', ->
359
+ beforeEach ->
360
+ input =
361
+ members:
362
+ config:
363
+ type: 'structure'
364
+ members:
365
+ settings:
366
+ type: 'structure'
367
+ members:
368
+ enabled: type: 'boolean'
369
+
370
+ it 'throws helpful messages for unknown params', ->
371
+ msg = 'Unexpected key \'fake\' found in params'
372
+ expectError msg, fake: 'value'
373
+
374
+ it 'throws helpful messages for nested unknown params', ->
375
+ msg = 'Unexpected key \'fake\' found in params.config.settings'
376
+ expectError msg, config: settings: fake: 'value'
377
+
378
+ it 'throws helpful messages for missing required params', ->
379
+ msg = 'Missing required key \'needed\' in params.config.settings'
380
+ input.members.config.members.settings.required = ['needed']
381
+ expectError msg, config: settings: {}
382
+
383
+ it 'throws helpul messages for invalid structures', ->
384
+ msg = 'Expected params.config.settings to be a structure'
385
+ expectError msg, config: settings: 'abc'
386
+
387
+ it 'throws helpul messages for invalid lists', ->
388
+ msg = 'Expected params.config.settings.tags to be an Array'
389
+ input.members.config.members.settings.members.tags = type: 'list', member: {}
390
+ expectError msg, config: settings: tags: 123
391
+
392
+ it 'throws helpful messages for invalid list members', ->
393
+ msg = 'Expected params.config.items[1].value to be a number'
394
+ input.members.config.members.items =
395
+ type: 'list',
396
+ member:
397
+ type: 'structure',
398
+ members:
399
+ value: type: 'integer'
400
+
401
+ expectError msg, config: items:
402
+ [{value: 123}, {value: 'abc'}, {value: 321}]
403
+
404
+ it 'throws helpful messages for invalid maps', ->
405
+ msg = 'Expected params.config.settings.tags to be a map'
406
+ input.members.config.members.settings.members.tags =
407
+ type: 'map',
408
+ key: {}
409
+ value: {}
410
+
411
+ expectError msg, config: settings: tags: '123'
412
+
413
+ it 'throws helpful messages for invalid map members', ->
414
+ msg = 'Expected params.config.counts[\'red\'] to be a number'
415
+ input.members.config.members.counts =
416
+ type: 'map',
417
+ value: type: 'integer'
418
+
419
+ expectError msg, config: counts: red: true
420
+
421
+ it 'throws helpful messages for invalid strings', ->
422
+ msg = "Expected params.config.settings.name to be a string"
423
+ input.members.config.members.settings.members.name = type: 'string'
424
+ expectError msg, config: settings: name: 123
425
+
426
+ it 'throws helpful messages for invalid integers', ->
427
+ msg = "Expected params.config.settings.count to be a number"
428
+ input.members.config.members.settings.members.count = type: 'integer'
429
+ expectError msg, config: settings: count: 'invalid-integer'
430
+
431
+ it 'throws helpful messages for invalid timestamps', ->
432
+ msg = "Expected params.config.settings.when to be a " +
433
+ "Date object, ISO-8601 string, or a UNIX timestamp"
434
+ input.members.config.members.settings.members.when = type: 'timestamp'
435
+ expectError msg, config: settings: when: 'invalid-date'
436
+
437
+ it 'throws helpful messages for invalid booleans', ->
438
+ msg = "Expected params.config.settings.enabled to be a boolean"
439
+ expectError msg, config: settings: enabled: 'invalid-boolean'
440
+
441
+ it 'throws helpful messages for invalid floats', ->
442
+ msg = "Expected params.config.settings.value to be a number"
443
+ input.members.config.members.settings.members.value = type: 'float'
444
+ expectError msg, config: settings: value: 'invalid-float'
445
+
446
+ it 'throws helpful messages for invalid base64 params', ->
447
+ msg = "Expected params.config.settings.data to be a " +
448
+ "string, Buffer, Stream, Blob, or typed array object"
449
+ input.members.config.members.settings.members.data = type: 'base64'
450
+ expectError msg, config: settings: data: 123
451
+
452
+ it 'throws helpful messages for invalid binary params', ->
453
+ msg = "Expected params.config.settings.data to be a " +
454
+ "string, Buffer, Stream, Blob, or typed array object"
455
+ input.members.config.members.settings.members.data = type: 'binary'
456
+ expectError msg, config: settings: data: 123
@@ -0,0 +1,167 @@
1
+ helpers = require('../helpers')
2
+ AWS = helpers.AWS
3
+ Buffer = AWS.util.Buffer
4
+
5
+ svc = AWS.Protocol.Json
6
+ describe 'AWS.Protocol.Json', ->
7
+
8
+ MockJSONClient = AWS.util.inherit AWS.Service,
9
+ endpointPrefix: 'mockservice'
10
+ api: new AWS.Model.Api
11
+ metadata:
12
+ protocol: 'json'
13
+ targetPrefix: 'prefix'
14
+ operations:
15
+ OperationName:
16
+ input:
17
+ type: 'structure'
18
+ members: {}
19
+ output:
20
+ type: 'structure'
21
+ members:
22
+ i: type: 'integer'
23
+ b: type: 'binary'
24
+ s: type: 'string'
25
+
26
+ AWS.Service.defineMethods(MockJSONClient)
27
+
28
+ request = null
29
+ response = null
30
+ service = null
31
+
32
+ beforeEach ->
33
+ service = new MockJSONClient(region: 'region')
34
+ request = new AWS.Request(service, 'operationName')
35
+ response = request.response
36
+
37
+ describe 'buildRequest', ->
38
+ buildRequest = ->
39
+ svc.buildRequest(request)
40
+
41
+ it 'should use POST method requests', ->
42
+ buildRequest()
43
+ expect(request.httpRequest.method).toEqual('POST')
44
+
45
+ it 'should perform all operations on root (/)', ->
46
+ buildRequest()
47
+ expect(request.httpRequest.path).toEqual('/')
48
+
49
+ it 'allows mounted path to be specified', ->
50
+ service = new MockJSONClient(endpoint: 'https://localhost/foo/bar')
51
+ request = new AWS.Request(service, 'operationName')
52
+ buildRequest()
53
+ expect(request.httpRequest.path).toEqual('/foo/bar')
54
+
55
+ it 'should set Content-Type header', ->
56
+ buildRequest()
57
+ expect(request.httpRequest.headers['Content-Type']).
58
+ toEqual('application/x-amz-json-1.0')
59
+
60
+ it 'should set X-Amz-Target header', ->
61
+ buildRequest()
62
+ expect(request.httpRequest.headers['X-Amz-Target']).
63
+ toEqual('prefix.OperationName')
64
+
65
+ it 'should set the body to JSON serialized params', ->
66
+ service.api.operations.operationName.input.members.foo =
67
+ new AWS.Model.Shape.create({type: 'string'}, api: service.api)
68
+ request.params = foo: 'bar'
69
+ buildRequest()
70
+ expect(request.httpRequest.body).toEqual('{"foo":"bar"}')
71
+
72
+ it 'should preserve numeric types', ->
73
+ service.api.operations.operationName.input.members.count =
74
+ new AWS.Model.Shape.create({type: 'integer'}, api: service.api)
75
+ request.params = count: 3
76
+ buildRequest()
77
+ expect(request.httpRequest.body).toEqual('{"count":3}')
78
+
79
+ describe 'extractError', ->
80
+ extractError = (body) ->
81
+ response.httpResponse.statusCode = 500
82
+ response.httpResponse.body = new Buffer(body)
83
+ svc.extractError(response)
84
+
85
+ it 'removes prefixes from the error code', ->
86
+ extractError '{"__type":"com.amazon.coral.service#ErrorCode" }'
87
+ expect(response.error instanceof Error).toBeTruthy()
88
+ expect(response.error.code).toEqual('ErrorCode')
89
+ expect(response.data).toEqual(null)
90
+
91
+ it 'returns the full code when a # is not present', ->
92
+ extractError '{"__type":"ErrorCode" }'
93
+ expect(response.error instanceof Error).toBeTruthy()
94
+ expect(response.error.code).toEqual('ErrorCode')
95
+ expect(response.data).toEqual(null)
96
+
97
+ it 'returns the status code when the body is blank', ->
98
+ extractError ''
99
+ expect(response.error instanceof Error).toBeTruthy()
100
+ expect(response.error.code).toEqual(500)
101
+ expect(response.error.message).toEqual(null)
102
+ expect(response.data).toEqual(null)
103
+
104
+ it 'returns UnknownError when the error type is not set', ->
105
+ extractError '{"message":"Error Message" }'
106
+ expect(response.error instanceof Error).toBeTruthy()
107
+ expect(response.error.code).toEqual('UnknownError')
108
+ expect(response.error.message).toEqual('Error Message')
109
+ expect(response.data).toEqual(null)
110
+
111
+ it 'returns null for the message when not present', ->
112
+ extractError '{"__type":"ErrorCode" }'
113
+ expect(response.error instanceof Error).toBeTruthy()
114
+ expect(response.error.message).toEqual(null)
115
+ expect(response.data).toEqual(null)
116
+
117
+ it 'returns the message when present', ->
118
+ extractError '{"__type":"ErrorCode", "message":"Error Message" }'
119
+ expect(response.error instanceof Error).toBeTruthy()
120
+ expect(response.error.message).toEqual('Error Message')
121
+ expect(response.data).toEqual(null)
122
+
123
+ # DynamoDB and SWF return error message properties with different case
124
+ it 'returns the message when the message property is upper-cased', ->
125
+ extractError '{"__type":"ErrorCode", "Message":"Error Message" }'
126
+ expect(response.error instanceof Error).toBeTruthy()
127
+ expect(response.error.message).toEqual('Error Message')
128
+ expect(response.data).toEqual(null)
129
+
130
+ it 'returns a special message for RequestEntityToLarge errors', ->
131
+ extractError '{"__type":"RequestEntityTooLarge" }'
132
+ expect(response.error instanceof Error).toBeTruthy()
133
+ expect(response.error.message).toEqual('Request body must be less than 1 MB')
134
+ expect(response.data).toEqual(null)
135
+
136
+ it 'extracts error type from "code" key (Glacier)', ->
137
+ extractError '{"code":"InvalidParameter"}'
138
+ expect(response.error instanceof Error).toBeTruthy()
139
+ expect(response.error.code).toEqual('InvalidParameter')
140
+
141
+ describe 'extractData', ->
142
+ extractData = (body) ->
143
+ response.httpResponse.statusCode = 200
144
+ response.httpResponse.body = new Buffer(body)
145
+ svc.extractData(response)
146
+
147
+ it 'JSON parses http response bodies', ->
148
+ extractData '{"i":1, "b":"AQID"}'
149
+ expect(response.error).toEqual(null)
150
+ expect(response.data.i).toEqual(1)
151
+ expect(response.data.b.toString()).toEqual('\u0001\u0002\u0003')
152
+
153
+ it 'returns raw data if convertResponseTypes is false', ->
154
+ service.config.convertResponseTypes = false
155
+ extractData '{"i":1, "b":"AQID"}'
156
+ expect(response.data.i).toEqual(1)
157
+ expect(response.data.b.toString()).toEqual('AQID')
158
+
159
+ it 'returns an empty object when the body is an empty string', ->
160
+ extractData ''
161
+ expect(response.error).toEqual(null)
162
+ expect(response.data).toEqual({})
163
+
164
+ it 'returns an empty object when the body is null', ->
165
+ extractData ''
166
+ expect(response.error).toEqual(null)
167
+ expect(response.data).toEqual({})