vagrant-unbundled 1.8.4.2 → 1.8.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +52 -0
- data/Gemfile.lock +9 -7
- data/RELEASE.md +37 -14
- data/lib/vagrant/action/builtin/box_add.rb +3 -1
- data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +5 -0
- data/lib/vagrant/box_collection.rb +2 -1
- data/lib/vagrant/bundler.rb +36 -1
- data/lib/vagrant/errors.rb +16 -8
- data/lib/vagrant/plugin/state_file.rb +8 -1
- data/lib/vagrant/util/platform.rb +1 -1
- data/plugins/guests/arch/cap/change_host_name.rb +13 -10
- data/plugins/guests/arch/cap/configure_networks.rb +11 -8
- data/plugins/guests/arch/cap/nfs.rb +35 -0
- data/plugins/guests/arch/cap/rsync.rb +16 -0
- data/plugins/guests/arch/cap/smb.rb +17 -0
- data/plugins/guests/arch/plugin.rb +28 -3
- data/plugins/guests/atomic/cap/change_host_name.rb +13 -10
- data/plugins/guests/atomic/plugin.rb +3 -3
- data/plugins/guests/{netbsd → bsd}/cap/halt.rb +2 -2
- data/plugins/guests/bsd/cap/nfs.rb +49 -0
- data/plugins/guests/bsd/cap/public_key.rb +65 -0
- data/plugins/guests/bsd/cap/virtualbox.rb +16 -0
- data/plugins/guests/bsd/guest.rb +9 -0
- data/plugins/guests/bsd/plugin.rb +40 -0
- data/plugins/guests/coreos/cap/change_host_name.rb +1 -1
- data/plugins/guests/coreos/plugin.rb +4 -4
- data/plugins/guests/darwin/cap/change_host_name.rb +4 -1
- data/plugins/guests/darwin/cap/configure_networks.rb +12 -5
- data/plugins/guests/darwin/cap/halt.rb +3 -1
- data/plugins/guests/darwin/cap/rsync.rb +7 -4
- data/plugins/guests/darwin/plugin.rb +13 -28
- data/plugins/guests/debian/cap/change_host_name.rb +14 -15
- data/plugins/guests/debian/cap/configure_networks.rb +2 -6
- data/plugins/guests/debian/cap/{nfs_client.rb → nfs.rb} +2 -1
- data/plugins/guests/debian/cap/rsync.rb +5 -6
- data/plugins/guests/debian/plugin.rb +8 -8
- data/plugins/guests/esxi/cap/mount_nfs_folder.rb +2 -2
- data/plugins/guests/esxi/plugin.rb +6 -6
- data/plugins/guests/fedora/cap/flavor.rb +1 -1
- data/plugins/guests/fedora/plugin.rb +2 -17
- data/plugins/guests/freebsd/cap/change_host_name.rb +2 -3
- data/plugins/guests/freebsd/cap/rsync.rb +7 -4
- data/plugins/guests/freebsd/plugin.rb +9 -29
- data/plugins/guests/funtoo/plugin.rb +3 -8
- data/plugins/guests/gentoo/cap/change_host_name.rb +21 -6
- data/plugins/guests/gentoo/cap/configure_networks.rb +35 -26
- data/plugins/guests/gentoo/plugin.rb +4 -4
- data/plugins/guests/linux/cap/choose_addressable_ip_addr.rb +2 -3
- data/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +31 -45
- data/plugins/guests/linux/cap/network_interfaces.rb +20 -0
- data/plugins/guests/linux/cap/nfs.rb +57 -0
- data/plugins/guests/linux/cap/public_key.rb +65 -0
- data/plugins/guests/linux/cap/rsync.rb +7 -4
- data/plugins/guests/linux/plugin.rb +30 -25
- data/plugins/guests/mint/plugin.rb +1 -1
- data/plugins/guests/netbsd/plugin.rb +10 -30
- data/plugins/guests/nixos/plugin.rb +5 -5
- data/plugins/guests/omnios/cap/change_host_name.rb +1 -1
- data/plugins/guests/omnios/plugin.rb +4 -4
- data/plugins/guests/openbsd/cap/change_host_name.rb +21 -3
- data/plugins/guests/openbsd/plugin.rb +10 -30
- data/plugins/guests/photon/cap/change_host_name.rb +1 -1
- data/plugins/guests/photon/plugin.rb +4 -4
- data/plugins/guests/pld/cap/change_host_name.rb +1 -1
- data/plugins/guests/pld/plugin.rb +4 -4
- data/plugins/guests/redhat/cap/change_host_name.rb +4 -3
- data/plugins/guests/redhat/cap/configure_networks.rb +1 -24
- data/plugins/guests/redhat/plugin.rb +7 -7
- data/plugins/guests/slackware/cap/change_host_name.rb +1 -1
- data/plugins/guests/slackware/cap/configure_networks.rb +1 -5
- data/plugins/guests/slackware/plugin.rb +3 -3
- data/plugins/guests/smartos/plugin.rb +12 -12
- data/plugins/guests/solaris/plugin.rb +14 -14
- data/plugins/guests/solaris11/plugin.rb +12 -12
- data/plugins/guests/suse/cap/change_host_name.rb +1 -1
- data/plugins/guests/suse/cap/configure_networks.rb +1 -5
- data/plugins/guests/suse/plugin.rb +8 -8
- data/plugins/guests/tinycore/cap/mount_nfs.rb +2 -2
- data/plugins/guests/tinycore/plugin.rb +7 -7
- data/plugins/guests/trisquel/plugin.rb +1 -1
- data/plugins/guests/ubuntu/guest.rb +1 -1
- data/plugins/guests/ubuntu/plugin.rb +1 -6
- data/plugins/guests/windows/plugin.rb +2 -2
- data/plugins/kernel_v2/config/vm.rb +8 -1
- data/plugins/providers/hyperv/scripts/get_vm_status.ps1 +25 -5
- data/plugins/providers/virtualbox/driver/meta.rb +1 -0
- data/plugins/providers/virtualbox/driver/version_5_1.rb +734 -0
- data/plugins/providers/virtualbox/plugin.rb +1 -0
- data/plugins/synced_folders/nfs/synced_folder.rb +10 -2
- data/plugins/synced_folders/rsync/helper.rb +11 -4
- data/scripts/{bintray_upload.sh → sign.sh} +0 -0
- data/templates/guests/arch/network_static.erb +3 -3
- data/templates/guests/arch/network_static6.erb +8 -0
- data/templates/guests/freebsd/network_static6.erb +6 -0
- data/templates/guests/funtoo/network_static6.erb +9 -0
- data/templates/guests/gentoo/network_dhcp.erb +1 -1
- data/templates/guests/gentoo/network_static.erb +4 -4
- data/templates/guests/gentoo/network_static6.erb +7 -0
- data/templates/guests/redhat/network_dhcp.erb +1 -1
- data/templates/guests/redhat/network_static.erb +4 -1
- data/templates/guests/{fedora → redhat}/network_static6.erb +5 -2
- data/templates/locales/en.yml +40 -6
- data/test/unit/plugins/guests/arch/cap/change_host_name_test.rb +6 -6
- data/test/unit/plugins/guests/arch/cap/configure_networks_test.rb +20 -15
- data/test/unit/plugins/guests/arch/cap/rsync_test.rb +30 -0
- data/test/unit/plugins/guests/arch/cap/smb_test.rb +38 -0
- data/test/unit/plugins/guests/atomic/cap/change_host_name_test.rb +9 -8
- data/test/unit/plugins/guests/{freebsd → bsd}/cap/halt_test.rb +11 -10
- data/test/unit/plugins/guests/{freebsd → bsd}/cap/insert_public_key_test.rb +7 -6
- data/test/unit/plugins/guests/bsd/cap/nfs_test.rb +68 -0
- data/test/unit/plugins/guests/coreos/cap/change_host_name_test.rb +5 -5
- data/test/unit/plugins/guests/darwin/cap/change_host_name_test.rb +5 -5
- data/test/unit/plugins/guests/darwin/cap/halt_test.rb +36 -0
- data/test/unit/plugins/guests/debian/cap/change_host_name_test.rb +3 -5
- data/test/unit/plugins/guests/debian/cap/configure_networks_test.rb +13 -9
- data/test/unit/plugins/guests/debian/cap/rsync_test.rb +3 -11
- data/test/unit/plugins/guests/freebsd/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/linux/cap/mount_nfs_test.rb +16 -3
- data/test/unit/plugins/guests/omnios/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/photon/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/pld/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb +4 -3
- data/test/unit/plugins/guests/redhat/cap/configure_networks_test.rb +17 -33
- data/test/unit/plugins/guests/slackware/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/slackware/cap/configure_networks_test.rb +8 -4
- data/test/unit/plugins/guests/suse/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/suse/cap/configure_networks_test.rb +13 -16
- data/test/unit/plugins/kernel_v2/config/vm_test.rb +10 -2
- data/test/unit/templates/guests/arch/network_static_test.rb +4 -2
- data/test/unit/templates/guests/gentoo/network_dhcp_test.rb +2 -2
- data/test/unit/templates/guests/gentoo/network_static_test.rb +10 -10
- data/test/unit/templates/guests/redhat/network_dhcp_test.rb +2 -2
- data/test/unit/templates/guests/redhat/network_static_test.rb +9 -9
- data/vagrant.gemspec +3 -3
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/CHANGELOG.md +1 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/CONTRIBUTING.md +38 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/LICENSE.txt +22 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/README.md +297 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/bin/listen +12 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/base.rb +141 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/bsd.rb +106 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/config.rb +26 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/darwin.rb +92 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/linux.rb +106 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/polling.rb +37 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/windows.rb +98 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter.rb +45 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/backend.rb +38 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/change.rb +76 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/cli.rb +65 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/directory.rb +87 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/config.rb +55 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/loop.rb +117 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/processor.rb +122 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/queue.rb +55 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/file.rb +80 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/fsm.rb +132 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/internals/thread_pool.rb +29 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/listener/config.rb +41 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/listener.rb +133 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/logger.rb +32 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/options.rb +23 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/queue_optimizer.rb +132 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record/entry.rb +64 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record/symlink_detector.rb +39 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record.rb +118 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/silencer/controller.rb +48 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/silencer.rb +97 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/version.rb +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen.rb +57 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.gitignore +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.rspec +2 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.rubocop-disables.yml +384 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.rubocop.yml +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.travis.yml +43 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/AUTHORS +98 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/Gemfile +11 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/LICENSE +21 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/README.md +667 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/Rakefile +132 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/bin/restclient +92 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/history.md +310 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/rest-client.rb +2 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/rest_client.rb +2 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/abstract_response.rb +226 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/exceptions.rb +244 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/params_array.rb +72 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/payload.rb +209 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/platform.rb +49 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/raw_response.rb +38 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb +904 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/resource.rb +168 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/response.rb +80 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/utils.rb +235 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/version.rb +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/windows/root_certs.rb +105 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/windows.rb +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient.rb +184 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/rest-client.gemspec +31 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/rest-client.windows.gemspec +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/helpers.rb +22 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/_lib.rb +1 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/244b5494.0 +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/81b9768f.0 +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/README +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/digicert.crt +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/415660c1.0 +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/7651b327.0 +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/README +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/verisign.crt +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/certs/digicert.crt +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/certs/verisign.crt +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/httpbin_spec.rb +86 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/integration_spec.rb +125 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/request_spec.rb +127 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/spec_helper.rb +29 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/_lib.rb +1 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/abstract_response_spec.rb +145 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/exceptions_spec.rb +108 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/master_shake.jpg +0 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/params_array_spec.rb +36 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/payload_spec.rb +263 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/raw_response_spec.rb +18 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/request2_spec.rb +54 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/request_spec.rb +1265 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/resource_spec.rb +130 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/response_spec.rb +241 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/restclient_spec.rb +79 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/utils_spec.rb +147 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/windows/root_certs_spec.rb +22 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.gitignore +10 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.rspec +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.rubocop.yml +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.travis.yml +11 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/LICENSE.txt +21 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/README.md +151 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/logger.rb +16 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/quiet.rb +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/ruby_version.rb +58 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/travis/ruby_version.rb +59 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/travis.rb +58 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/version.rb +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/warning.rb +97 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep.rb +2 -0
- data/vendor/bundle/ruby/2.3.0/specifications/listen-3.1.5.gemspec +44 -0
- data/vendor/bundle/ruby/2.3.0/specifications/rest-client-2.0.0.gemspec +60 -0
- data/vendor/bundle/ruby/2.3.0/specifications/ruby_dep-1.4.0.gemspec +34 -0
- data/version.txt +1 -1
- metadata +147 -44
- data/plugins/guests/darwin/cap/insert_public_key.rb +0 -33
- data/plugins/guests/darwin/cap/mount_nfs_folder.rb +0 -37
- data/plugins/guests/darwin/cap/remove_public_key.rb +0 -21
- data/plugins/guests/fedora/cap/change_host_name.rb +0 -29
- data/plugins/guests/fedora/cap/configure_networks.rb +0 -135
- data/plugins/guests/fedora/cap/network_scripts_dir.rb +0 -15
- data/plugins/guests/freebsd/cap/halt.rb +0 -16
- data/plugins/guests/freebsd/cap/insert_public_key.rb +0 -34
- data/plugins/guests/freebsd/cap/mount_nfs_folder.rb +0 -24
- data/plugins/guests/freebsd/cap/remove_public_key.rb +0 -21
- data/plugins/guests/funtoo/cap/change_host_name.rb +0 -17
- data/plugins/guests/linux/cap/insert_public_key.rb +0 -31
- data/plugins/guests/linux/cap/mount_nfs.rb +0 -50
- data/plugins/guests/linux/cap/nfs_client.rb +0 -11
- data/plugins/guests/linux/cap/remove_public_key.rb +0 -24
- data/plugins/guests/netbsd/cap/insert_public_key.rb +0 -21
- data/plugins/guests/netbsd/cap/mount_nfs_folder.rb +0 -17
- data/plugins/guests/netbsd/cap/remove_public_key.rb +0 -21
- data/plugins/guests/openbsd/cap/halt.rb +0 -16
- data/plugins/guests/openbsd/cap/insert_public_key.rb +0 -21
- data/plugins/guests/openbsd/cap/mount_nfs_folder.rb +0 -14
- data/plugins/guests/openbsd/cap/remove_public_key.rb +0 -21
- data/plugins/guests/ubuntu/cap/change_host_name.rb +0 -52
- data/templates/guests/fedora/network_dhcp.erb +0 -6
- data/templates/guests/fedora/network_static.erb +0 -16
- data/test/unit/plugins/guests/freebsd/cap/mount_nfs_folder_test.rb +0 -53
- data/test/unit/plugins/guests/ubuntu/cap/change_host_name_test.rb +0 -42
- data/test/unit/templates/guests/fedora/network_dhcp_test.rb +0 -21
- data/test/unit/templates/guests/fedora/network_static6_test.rb +0 -25
- data/test/unit/templates/guests/fedora/network_static_test.rb +0 -71
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '_lib'
|
2
|
+
|
3
|
+
describe RestClient::RawResponse do
|
4
|
+
before do
|
5
|
+
@tf = double("Tempfile", :read => "the answer is 42", :open => true)
|
6
|
+
@net_http_res = double('net http response')
|
7
|
+
@request = double('http request')
|
8
|
+
@response = RestClient::RawResponse.new(@tf, @net_http_res, @request)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "behaves like string" do
|
12
|
+
expect(@response.to_s).to eq 'the answer is 42'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "exposes a Tempfile" do
|
16
|
+
expect(@response.file).to eq @tf
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '_lib'
|
2
|
+
|
3
|
+
describe RestClient::Request do
|
4
|
+
|
5
|
+
context 'params for GET requests' do
|
6
|
+
it "manage params for get requests" do
|
7
|
+
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
8
|
+
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body).to eq 'foo'
|
9
|
+
|
10
|
+
stub_request(:get, 'http://some/resource').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
11
|
+
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body).to eq 'foo'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'adds GET params when params are present in URL' do
|
15
|
+
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
16
|
+
expect(RestClient::Request.execute(:url => 'http://some/resource?a=b', :method => :get, :headers => {:foo => :bar, :params => {:c => 'd'}}).body).to eq 'foo'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'encodes nested GET params' do
|
20
|
+
stub_request(:get, 'http://some/resource?a[foo][]=1&a[foo][]=2&a[bar]&b=foo+bar&math=2+%2B+2+%3D%3D+4').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
21
|
+
expect(RestClient::Request.execute(url: 'http://some/resource', method: :get, headers: {
|
22
|
+
params: {
|
23
|
+
a: {
|
24
|
+
foo: [1,2],
|
25
|
+
bar: nil,
|
26
|
+
},
|
27
|
+
b: 'foo bar',
|
28
|
+
math: '2 + 2 == 4',
|
29
|
+
}
|
30
|
+
}).body).to eq 'foo'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can use a block to process response" do
|
36
|
+
response_value = nil
|
37
|
+
block = proc do |http_response|
|
38
|
+
response_value = http_response.body
|
39
|
+
end
|
40
|
+
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
41
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}, :block_response => block)
|
42
|
+
expect(response_value).to eq "foo"
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'closes payload if not nil' do
|
46
|
+
test_file = File.new(File.join( File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))
|
47
|
+
|
48
|
+
stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
49
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
|
50
|
+
|
51
|
+
expect(test_file.closed?).to be true
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,1265 @@
|
|
1
|
+
require_relative './_lib'
|
2
|
+
|
3
|
+
describe RestClient::Request, :include_helpers do
|
4
|
+
before do
|
5
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
|
6
|
+
|
7
|
+
@uri = double("uri")
|
8
|
+
allow(@uri).to receive(:request_uri).and_return('/resource')
|
9
|
+
allow(@uri).to receive(:hostname).and_return('some')
|
10
|
+
allow(@uri).to receive(:port).and_return(80)
|
11
|
+
|
12
|
+
@net = double("net::http base")
|
13
|
+
@http = double("net::http connection")
|
14
|
+
|
15
|
+
allow(Net::HTTP).to receive(:new).and_return(@net)
|
16
|
+
|
17
|
+
allow(@net).to receive(:start).and_yield(@http)
|
18
|
+
allow(@net).to receive(:use_ssl=)
|
19
|
+
allow(@net).to receive(:verify_mode=)
|
20
|
+
allow(@net).to receive(:verify_callback=)
|
21
|
+
allow(@net).to receive(:ciphers=)
|
22
|
+
allow(@net).to receive(:cert_store=)
|
23
|
+
RestClient.log = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "accept */* mimetype" do
|
27
|
+
expect(@request.default_headers[:accept]).to eq '*/*'
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "compression" do
|
31
|
+
|
32
|
+
it "decodes an uncompressed result body by passing it straight through" do
|
33
|
+
expect(RestClient::Request.decode(nil, 'xyz')).to eq 'xyz'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "doesn't fail for nil bodies" do
|
37
|
+
expect(RestClient::Request.decode('gzip', nil)).to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "decodes a gzip body" do
|
42
|
+
expect(RestClient::Request.decode('gzip', "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000")).to eq "i'm gziped\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "ingores gzip for empty bodies" do
|
46
|
+
expect(RestClient::Request.decode('gzip', '')).to be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it "decodes a deflated body" do
|
50
|
+
expect(RestClient::Request.decode('deflate', "x\234+\316\317MUHIM\313I,IMQ(I\255(\001\000A\223\006\363")).to eq "some deflated text"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "processes a successful result" do
|
55
|
+
res = response_double
|
56
|
+
allow(res).to receive(:code).and_return("200")
|
57
|
+
allow(res).to receive(:body).and_return('body')
|
58
|
+
allow(res).to receive(:[]).with('content-encoding').and_return(nil)
|
59
|
+
expect(@request.send(:process_result, res).body).to eq 'body'
|
60
|
+
expect(@request.send(:process_result, res).to_s).to eq 'body'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "doesn't classify successful requests as failed" do
|
64
|
+
203.upto(207) do |code|
|
65
|
+
res = response_double
|
66
|
+
allow(res).to receive(:code).and_return(code.to_s)
|
67
|
+
allow(res).to receive(:body).and_return("")
|
68
|
+
allow(res).to receive(:[]).with('content-encoding').and_return(nil)
|
69
|
+
expect(@request.send(:process_result, res)).to be_empty
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '.normalize_url' do
|
74
|
+
it "adds http:// to the front of resources specified in the syntax example.com/resource" do
|
75
|
+
expect(@request.normalize_url('example.com/resource')).to eq 'http://example.com/resource'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'adds http:// to resources containing a colon' do
|
79
|
+
expect(@request.normalize_url('example.com:1234')).to eq 'http://example.com:1234'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'does not add http:// to the front of https resources' do
|
83
|
+
expect(@request.normalize_url('https://example.com/resource')).to eq 'https://example.com/resource'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'does not add http:// to the front of capital HTTP resources' do
|
87
|
+
expect(@request.normalize_url('HTTP://example.com/resource')).to eq 'HTTP://example.com/resource'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'does not add http:// to the front of capital HTTPS resources' do
|
91
|
+
expect(@request.normalize_url('HTTPS://example.com/resource')).to eq 'HTTPS://example.com/resource'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'raises with invalid URI' do
|
95
|
+
expect {
|
96
|
+
RestClient::Request.new(method: :get, url: 'http://a@b:c')
|
97
|
+
}.to raise_error(URI::InvalidURIError)
|
98
|
+
expect {
|
99
|
+
RestClient::Request.new(method: :get, url: 'http://::')
|
100
|
+
}.to raise_error(URI::InvalidURIError)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "user - password" do
|
105
|
+
it "extracts the username and password when parsing http://user:password@example.com/" do
|
106
|
+
@request.send(:parse_url_with_auth!, 'http://joe:pass1@example.com/resource')
|
107
|
+
expect(@request.user).to eq 'joe'
|
108
|
+
expect(@request.password).to eq 'pass1'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "extracts with escaping the username and password when parsing http://user:password@example.com/" do
|
112
|
+
@request.send(:parse_url_with_auth!, 'http://joe%20:pass1@example.com/resource')
|
113
|
+
expect(@request.user).to eq 'joe '
|
114
|
+
expect(@request.password).to eq 'pass1'
|
115
|
+
end
|
116
|
+
|
117
|
+
it "doesn't overwrite user and password (which may have already been set by the Resource constructor) if there is no user/password in the url" do
|
118
|
+
request = RestClient::Request.new(method: :get, url: 'http://example.com/resource', user: 'beth', password: 'pass2')
|
119
|
+
expect(request.user).to eq 'beth'
|
120
|
+
expect(request.password).to eq 'pass2'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'uses the username and password from the URL' do
|
124
|
+
request = RestClient::Request.new(method: :get, url: 'http://person:secret@example.com/resource')
|
125
|
+
expect(request.user).to eq 'person'
|
126
|
+
expect(request.password).to eq 'secret'
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'overrides URL user/pass with explicit options' do
|
130
|
+
request = RestClient::Request.new(method: :get, url: 'http://person:secret@example.com/resource', user: 'beth', password: 'pass2')
|
131
|
+
expect(request.user).to eq 'beth'
|
132
|
+
expect(request.password).to eq 'pass2'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "correctly formats cookies provided to the constructor" do
|
137
|
+
cookies_arr = [
|
138
|
+
HTTP::Cookie.new('session_id', '1', domain: 'example.com', path: '/'),
|
139
|
+
HTTP::Cookie.new('user_id', 'someone', domain: 'example.com', path: '/'),
|
140
|
+
]
|
141
|
+
|
142
|
+
jar = HTTP::CookieJar.new
|
143
|
+
cookies_arr.each {|c| jar << c }
|
144
|
+
|
145
|
+
# test Hash, HTTP::CookieJar, and Array<HTTP::Cookie> modes
|
146
|
+
[
|
147
|
+
{session_id: '1', user_id: 'someone'},
|
148
|
+
jar,
|
149
|
+
cookies_arr
|
150
|
+
].each do |cookies|
|
151
|
+
[true, false].each do |in_headers|
|
152
|
+
if in_headers
|
153
|
+
opts = {headers: {cookies: cookies}}
|
154
|
+
else
|
155
|
+
opts = {cookies: cookies}
|
156
|
+
end
|
157
|
+
|
158
|
+
request = RestClient::Request.new(method: :get, url: 'example.com', **opts)
|
159
|
+
expect(request).to receive(:default_headers).and_return({'Foo' => 'bar'})
|
160
|
+
expect(request.make_headers({})).to eq({'Foo' => 'bar', 'Cookie' => 'session_id=1; user_id=someone'})
|
161
|
+
expect(request.make_cookie_header).to eq 'session_id=1; user_id=someone'
|
162
|
+
expect(request.cookies).to eq({'session_id' => '1', 'user_id' => 'someone'})
|
163
|
+
expect(request.cookie_jar.cookies.length).to eq 2
|
164
|
+
expect(request.cookie_jar.object_id).not_to eq jar.object_id # make sure we dup it
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# test with no cookies
|
169
|
+
request = RestClient::Request.new(method: :get, url: 'example.com')
|
170
|
+
expect(request).to receive(:default_headers).and_return({'Foo' => 'bar'})
|
171
|
+
expect(request.make_headers({})).to eq({'Foo' => 'bar'})
|
172
|
+
expect(request.make_cookie_header).to be_nil
|
173
|
+
expect(request.cookies).to eq({})
|
174
|
+
expect(request.cookie_jar.cookies.length).to eq 0
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'strips out cookies set for a different domain name' do
|
178
|
+
jar = HTTP::CookieJar.new
|
179
|
+
jar << HTTP::Cookie.new('session_id', '1', domain: 'other.example.com', path: '/')
|
180
|
+
jar << HTTP::Cookie.new('user_id', 'someone', domain: 'other.example.com', path: '/')
|
181
|
+
|
182
|
+
request = RestClient::Request.new(method: :get, url: 'www.example.com', cookies: jar)
|
183
|
+
expect(request).to receive(:default_headers).and_return({'Foo' => 'bar'})
|
184
|
+
expect(request.make_headers({})).to eq({'Foo' => 'bar'})
|
185
|
+
expect(request.make_cookie_header).to eq nil
|
186
|
+
expect(request.cookies).to eq({})
|
187
|
+
expect(request.cookie_jar.cookies.length).to eq 2
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'assumes default domain and path for cookies set by hash' do
|
191
|
+
request = RestClient::Request.new(method: :get, url: 'www.example.com', cookies: {'session_id' => '1'})
|
192
|
+
expect(request.cookie_jar.cookies.length).to eq 1
|
193
|
+
|
194
|
+
cookie = request.cookie_jar.cookies.first
|
195
|
+
expect(cookie).to be_a(HTTP::Cookie)
|
196
|
+
expect(cookie.domain).to eq('www.example.com')
|
197
|
+
expect(cookie.for_domain?).to be_truthy
|
198
|
+
expect(cookie.path).to eq('/')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'rejects or warns with contradictory cookie options' do
|
202
|
+
# same opt in two different places
|
203
|
+
expect {
|
204
|
+
RestClient::Request.new(method: :get, url: 'example.com',
|
205
|
+
cookies: {bar: '456'},
|
206
|
+
headers: {cookies: {foo: '123'}})
|
207
|
+
}.to raise_error(ArgumentError, /Cannot pass :cookies in Request.*headers/)
|
208
|
+
|
209
|
+
# :cookies opt and Cookie header
|
210
|
+
[
|
211
|
+
{cookies: {foo: '123'}, headers: {cookie: 'foo'}},
|
212
|
+
{cookies: {foo: '123'}, headers: {'Cookie' => 'foo'}},
|
213
|
+
{headers: {cookies: {foo: '123'}, cookie: 'foo'}},
|
214
|
+
{headers: {cookies: {foo: '123'}, 'Cookie' => 'foo'}},
|
215
|
+
].each do |opts|
|
216
|
+
expect(fake_stderr {
|
217
|
+
RestClient::Request.new(method: :get, url: 'example.com', **opts)
|
218
|
+
}).to match(/warning: overriding "Cookie" header with :cookies option/)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
it "does not escape or unescape cookies" do
|
223
|
+
cookie = 'Foo%20:Bar%0A~'
|
224
|
+
@request = RestClient::Request.new(:method => 'get', :url => 'example.com',
|
225
|
+
:cookies => {:test => cookie})
|
226
|
+
expect(@request).to receive(:default_headers).and_return({'Foo' => 'bar'})
|
227
|
+
expect(@request.make_headers({})).to eq({
|
228
|
+
'Foo' => 'bar',
|
229
|
+
'Cookie' => "test=#{cookie}"
|
230
|
+
})
|
231
|
+
end
|
232
|
+
|
233
|
+
it "rejects cookie names containing invalid characters" do
|
234
|
+
# Cookie validity is something of a mess, but we should reject the worst of
|
235
|
+
# the RFC 6265 (4.1.1) prohibited characters such as control characters.
|
236
|
+
|
237
|
+
['foo=bar', 'foo;bar', "foo\nbar"].each do |cookie_name|
|
238
|
+
expect {
|
239
|
+
RestClient::Request.new(:method => 'get', :url => 'example.com',
|
240
|
+
:cookies => {cookie_name => 'value'})
|
241
|
+
}.to raise_error(ArgumentError, /\AInvalid cookie name/i)
|
242
|
+
end
|
243
|
+
|
244
|
+
cookie_name = ''
|
245
|
+
expect {
|
246
|
+
RestClient::Request.new(:method => 'get', :url => 'example.com',
|
247
|
+
:cookies => {cookie_name => 'value'})
|
248
|
+
}.to raise_error(ArgumentError, /cookie name cannot be empty/i)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "rejects cookie values containing invalid characters" do
|
252
|
+
# Cookie validity is something of a mess, but we should reject the worst of
|
253
|
+
# the RFC 6265 (4.1.1) prohibited characters such as control characters.
|
254
|
+
|
255
|
+
["foo\tbar", "foo\nbar"].each do |cookie_value|
|
256
|
+
expect {
|
257
|
+
RestClient::Request.new(:method => 'get', :url => 'example.com',
|
258
|
+
:cookies => {'test' => cookie_value})
|
259
|
+
}.to raise_error(ArgumentError, /\AInvalid cookie value/i)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
it "uses netrc credentials" do
|
264
|
+
expect(Netrc).to receive(:read).and_return('example.com' => ['a', 'b'])
|
265
|
+
request = RestClient::Request.new(:method => :put, :url => 'http://example.com/', :payload => 'payload')
|
266
|
+
expect(request.user).to eq 'a'
|
267
|
+
expect(request.password).to eq 'b'
|
268
|
+
end
|
269
|
+
|
270
|
+
it "uses credentials in the url in preference to netrc" do
|
271
|
+
allow(Netrc).to receive(:read).and_return('example.com' => ['a', 'b'])
|
272
|
+
request = RestClient::Request.new(:method => :put, :url => 'http://joe%20:pass1@example.com/', :payload => 'payload')
|
273
|
+
expect(request.user).to eq 'joe '
|
274
|
+
expect(request.password).to eq 'pass1'
|
275
|
+
end
|
276
|
+
|
277
|
+
it "determines the Net::HTTP class to instantiate by the method name" do
|
278
|
+
expect(@request.net_http_request_class(:put)).to eq Net::HTTP::Put
|
279
|
+
end
|
280
|
+
|
281
|
+
describe "user headers" do
|
282
|
+
it "merges user headers with the default headers" do
|
283
|
+
expect(@request).to receive(:default_headers).and_return({ :accept => '*/*', :accept_encoding => 'gzip, deflate' })
|
284
|
+
headers = @request.make_headers("Accept" => "application/json", :accept_encoding => 'gzip')
|
285
|
+
expect(headers).to have_key "Accept-Encoding"
|
286
|
+
expect(headers["Accept-Encoding"]).to eq "gzip"
|
287
|
+
expect(headers).to have_key "Accept"
|
288
|
+
expect(headers["Accept"]).to eq "application/json"
|
289
|
+
end
|
290
|
+
|
291
|
+
it "prefers the user header when the same header exists in the defaults" do
|
292
|
+
expect(@request).to receive(:default_headers).and_return({ '1' => '2' })
|
293
|
+
headers = @request.make_headers('1' => '3')
|
294
|
+
expect(headers).to have_key('1')
|
295
|
+
expect(headers['1']).to eq '3'
|
296
|
+
end
|
297
|
+
|
298
|
+
it "converts user headers to string before calling CGI::unescape which fails on non string values" do
|
299
|
+
expect(@request).to receive(:default_headers).and_return({ '1' => '2' })
|
300
|
+
headers = @request.make_headers('1' => 3)
|
301
|
+
expect(headers).to have_key('1')
|
302
|
+
expect(headers['1']).to eq '3'
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe "header symbols" do
|
307
|
+
|
308
|
+
it "converts header symbols from :content_type to 'Content-Type'" do
|
309
|
+
expect(@request).to receive(:default_headers).and_return({})
|
310
|
+
headers = @request.make_headers(:content_type => 'abc')
|
311
|
+
expect(headers).to have_key('Content-Type')
|
312
|
+
expect(headers['Content-Type']).to eq 'abc'
|
313
|
+
end
|
314
|
+
|
315
|
+
it "converts content-type from extension to real content-type" do
|
316
|
+
expect(@request).to receive(:default_headers).and_return({})
|
317
|
+
headers = @request.make_headers(:content_type => 'json')
|
318
|
+
expect(headers).to have_key('Content-Type')
|
319
|
+
expect(headers['Content-Type']).to eq 'application/json'
|
320
|
+
end
|
321
|
+
|
322
|
+
it "converts accept from extension(s) to real content-type(s)" do
|
323
|
+
expect(@request).to receive(:default_headers).and_return({})
|
324
|
+
headers = @request.make_headers(:accept => 'json, mp3')
|
325
|
+
expect(headers).to have_key('Accept')
|
326
|
+
expect(headers['Accept']).to eq 'application/json, audio/mpeg'
|
327
|
+
|
328
|
+
expect(@request).to receive(:default_headers).and_return({})
|
329
|
+
headers = @request.make_headers(:accept => :json)
|
330
|
+
expect(headers).to have_key('Accept')
|
331
|
+
expect(headers['Accept']).to eq 'application/json'
|
332
|
+
end
|
333
|
+
|
334
|
+
it "only convert symbols in header" do
|
335
|
+
expect(@request).to receive(:default_headers).and_return({})
|
336
|
+
headers = @request.make_headers({:foo_bar => 'value', "bar_bar" => 'value'})
|
337
|
+
expect(headers['Foo-Bar']).to eq 'value'
|
338
|
+
expect(headers['bar_bar']).to eq 'value'
|
339
|
+
end
|
340
|
+
|
341
|
+
it "converts header values to strings" do
|
342
|
+
expect(@request.make_headers('A' => 1)['A']).to eq '1'
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it "executes by constructing the Net::HTTP object, headers, and payload and calling transmit" do
|
347
|
+
klass = double("net:http class")
|
348
|
+
expect(@request).to receive(:net_http_request_class).with('put').and_return(klass)
|
349
|
+
expect(klass).to receive(:new).and_return('result')
|
350
|
+
expect(@request).to receive(:transmit).with(@request.uri, 'result', kind_of(RestClient::Payload::Base))
|
351
|
+
@request.execute
|
352
|
+
end
|
353
|
+
|
354
|
+
it "IPv6: executes by constructing the Net::HTTP object, headers, and payload and calling transmit" do
|
355
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://[::1]/some/resource', :payload => 'payload')
|
356
|
+
klass = double("net:http class")
|
357
|
+
expect(@request).to receive(:net_http_request_class).with('put').and_return(klass)
|
358
|
+
|
359
|
+
if RUBY_VERSION >= "2.0.0"
|
360
|
+
expect(klass).to receive(:new).with(kind_of(URI), kind_of(Hash)).and_return('result')
|
361
|
+
else
|
362
|
+
expect(klass).to receive(:new).with(kind_of(String), kind_of(Hash)).and_return('result')
|
363
|
+
end
|
364
|
+
|
365
|
+
expect(@request).to receive(:transmit)
|
366
|
+
@request.execute
|
367
|
+
end
|
368
|
+
|
369
|
+
# TODO: almost none of these tests should actually call transmit, which is
|
370
|
+
# part of the private API
|
371
|
+
|
372
|
+
it "transmits the request with Net::HTTP" do
|
373
|
+
expect(@http).to receive(:request).with('req', 'payload')
|
374
|
+
expect(@request).to receive(:process_result)
|
375
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
376
|
+
end
|
377
|
+
|
378
|
+
# TODO: most of these payload tests are historical relics that actually
|
379
|
+
# belong in payload_spec.rb. Or we need new tests that actually cover the way
|
380
|
+
# that Request#initialize or Request#execute uses the payload.
|
381
|
+
describe "payload" do
|
382
|
+
it "sends nil payloads" do
|
383
|
+
expect(@http).to receive(:request).with('req', nil)
|
384
|
+
expect(@request).to receive(:process_result)
|
385
|
+
allow(@request).to receive(:response_log)
|
386
|
+
@request.send(:transmit, @uri, 'req', nil)
|
387
|
+
end
|
388
|
+
|
389
|
+
it "passes non-hash payloads straight through" do
|
390
|
+
expect(RestClient::Payload.generate("x").to_s).to eq "x"
|
391
|
+
end
|
392
|
+
|
393
|
+
it "converts a hash payload to urlencoded data" do
|
394
|
+
expect(RestClient::Payload.generate(:a => 'b c+d').to_s).to eq "a=b+c%2Bd"
|
395
|
+
end
|
396
|
+
|
397
|
+
it "accepts nested hashes in payload" do
|
398
|
+
payload = RestClient::Payload.generate(:user => { :name => 'joe', :location => { :country => 'USA', :state => 'CA' }}).to_s
|
399
|
+
expect(payload).to include('user[name]=joe')
|
400
|
+
expect(payload).to include('user[location][country]=USA')
|
401
|
+
expect(payload).to include('user[location][state]=CA')
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
it "set urlencoded content_type header on hash payloads" do
|
406
|
+
req = RestClient::Request.new(method: :post, url: 'http://some/resource', payload: {a: 1})
|
407
|
+
expect(req.processed_headers.fetch('Content-Type')).to eq 'application/x-www-form-urlencoded'
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "credentials" do
|
411
|
+
it "sets up the credentials prior to the request" do
|
412
|
+
allow(@http).to receive(:request)
|
413
|
+
|
414
|
+
allow(@request).to receive(:process_result)
|
415
|
+
allow(@request).to receive(:response_log)
|
416
|
+
|
417
|
+
allow(@request).to receive(:user).and_return('joe')
|
418
|
+
allow(@request).to receive(:password).and_return('mypass')
|
419
|
+
expect(@request).to receive(:setup_credentials).with('req')
|
420
|
+
|
421
|
+
@request.send(:transmit, @uri, 'req', nil)
|
422
|
+
end
|
423
|
+
|
424
|
+
it "does not attempt to send any credentials if user is nil" do
|
425
|
+
allow(@request).to receive(:user).and_return(nil)
|
426
|
+
req = double("request")
|
427
|
+
expect(req).not_to receive(:basic_auth)
|
428
|
+
@request.send(:setup_credentials, req)
|
429
|
+
end
|
430
|
+
|
431
|
+
it "setup credentials when there's a user" do
|
432
|
+
allow(@request).to receive(:user).and_return('joe')
|
433
|
+
allow(@request).to receive(:password).and_return('mypass')
|
434
|
+
req = double("request")
|
435
|
+
expect(req).to receive(:basic_auth).with('joe', 'mypass')
|
436
|
+
@request.send(:setup_credentials, req)
|
437
|
+
end
|
438
|
+
|
439
|
+
it "does not attempt to send credentials if Authorization header is set" do
|
440
|
+
@request.headers['Authorization'] = 'Token abc123'
|
441
|
+
allow(@request).to receive(:user).and_return('joe')
|
442
|
+
allow(@request).to receive(:password).and_return('mypass')
|
443
|
+
req = double("request")
|
444
|
+
expect(req).not_to receive(:basic_auth)
|
445
|
+
@request.send(:setup_credentials, req)
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
it "catches EOFError and shows the more informative ServerBrokeConnection" do
|
450
|
+
allow(@http).to receive(:request).and_raise(EOFError)
|
451
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::ServerBrokeConnection)
|
452
|
+
end
|
453
|
+
|
454
|
+
it "catches OpenSSL::SSL::SSLError and raise it back without more informative message" do
|
455
|
+
allow(@http).to receive(:request).and_raise(OpenSSL::SSL::SSLError)
|
456
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(OpenSSL::SSL::SSLError)
|
457
|
+
end
|
458
|
+
|
459
|
+
it "catches Timeout::Error and raise the more informative ReadTimeout" do
|
460
|
+
allow(@http).to receive(:request).and_raise(Timeout::Error)
|
461
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::Exceptions::ReadTimeout)
|
462
|
+
end
|
463
|
+
|
464
|
+
it "catches Errno::ETIMEDOUT and raise the more informative ReadTimeout" do
|
465
|
+
allow(@http).to receive(:request).and_raise(Errno::ETIMEDOUT)
|
466
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::Exceptions::ReadTimeout)
|
467
|
+
end
|
468
|
+
|
469
|
+
it "catches Net::ReadTimeout and raises RestClient's ReadTimeout",
|
470
|
+
:if => defined?(Net::ReadTimeout) do
|
471
|
+
allow(@http).to receive(:request).and_raise(Net::ReadTimeout)
|
472
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::Exceptions::ReadTimeout)
|
473
|
+
end
|
474
|
+
|
475
|
+
it "catches Net::OpenTimeout and raises RestClient's OpenTimeout",
|
476
|
+
:if => defined?(Net::OpenTimeout) do
|
477
|
+
allow(@http).to receive(:request).and_raise(Net::OpenTimeout)
|
478
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::Exceptions::OpenTimeout)
|
479
|
+
end
|
480
|
+
|
481
|
+
it "uses correct error message for ReadTimeout",
|
482
|
+
:if => defined?(Net::ReadTimeout) do
|
483
|
+
allow(@http).to receive(:request).and_raise(Net::ReadTimeout)
|
484
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::Exceptions::ReadTimeout, 'Timed out reading data from server')
|
485
|
+
end
|
486
|
+
|
487
|
+
it "uses correct error message for OpenTimeout",
|
488
|
+
:if => defined?(Net::OpenTimeout) do
|
489
|
+
allow(@http).to receive(:request).and_raise(Net::OpenTimeout)
|
490
|
+
expect { @request.send(:transmit, @uri, 'req', nil) }.to raise_error(RestClient::Exceptions::OpenTimeout, 'Timed out connecting to server')
|
491
|
+
end
|
492
|
+
|
493
|
+
|
494
|
+
it "class method execute wraps constructor" do
|
495
|
+
req = double("rest request")
|
496
|
+
expect(RestClient::Request).to receive(:new).with(1 => 2).and_return(req)
|
497
|
+
expect(req).to receive(:execute)
|
498
|
+
RestClient::Request.execute(1 => 2)
|
499
|
+
end
|
500
|
+
|
501
|
+
describe "exception" do
|
502
|
+
it "raises Unauthorized when the response is 401" do
|
503
|
+
res = response_double(:code => '401', :[] => ['content-encoding' => ''], :body => '' )
|
504
|
+
expect { @request.send(:process_result, res) }.to raise_error(RestClient::Unauthorized)
|
505
|
+
end
|
506
|
+
|
507
|
+
it "raises ResourceNotFound when the response is 404" do
|
508
|
+
res = response_double(:code => '404', :[] => ['content-encoding' => ''], :body => '' )
|
509
|
+
expect { @request.send(:process_result, res) }.to raise_error(RestClient::ResourceNotFound)
|
510
|
+
end
|
511
|
+
|
512
|
+
it "raises RequestFailed otherwise" do
|
513
|
+
res = response_double(:code => '500', :[] => ['content-encoding' => ''], :body => '' )
|
514
|
+
expect { @request.send(:process_result, res) }.to raise_error(RestClient::InternalServerError)
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
describe "block usage" do
|
519
|
+
it "returns what asked to" do
|
520
|
+
res = response_double(:code => '401', :[] => ['content-encoding' => ''], :body => '' )
|
521
|
+
expect(@request.send(:process_result, res){|response, request| "foo"}).to eq "foo"
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
describe "proxy" do
|
526
|
+
before do
|
527
|
+
# unstub Net::HTTP creation since we need to test it
|
528
|
+
allow(Net::HTTP).to receive(:new).and_call_original
|
529
|
+
|
530
|
+
@proxy_req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
|
531
|
+
end
|
532
|
+
|
533
|
+
it "creates a proxy class if a proxy url is given" do
|
534
|
+
allow(RestClient).to receive(:proxy).and_return("http://example.com/")
|
535
|
+
allow(RestClient).to receive(:proxy_set?).and_return(true)
|
536
|
+
expect(@proxy_req.net_http_object('host', 80).proxy?).to be true
|
537
|
+
end
|
538
|
+
|
539
|
+
it "creates a proxy class with the correct address if a IPv6 proxy url is given" do
|
540
|
+
allow(RestClient).to receive(:proxy).and_return("http://[::1]/")
|
541
|
+
allow(RestClient).to receive(:proxy_set?).and_return(true)
|
542
|
+
expect(@proxy_req.net_http_object('host', 80).proxy?).to be true
|
543
|
+
expect(@proxy_req.net_http_object('host', 80).proxy_address).to eq('::1')
|
544
|
+
end
|
545
|
+
|
546
|
+
it "creates a non-proxy class if a proxy url is not given" do
|
547
|
+
expect(@proxy_req.net_http_object('host', 80).proxy?).to be_falsey
|
548
|
+
end
|
549
|
+
|
550
|
+
it "disables proxy on a per-request basis" do
|
551
|
+
allow(RestClient).to receive(:proxy).and_return('http://example.com')
|
552
|
+
allow(RestClient).to receive(:proxy_set?).and_return(true)
|
553
|
+
expect(@proxy_req.net_http_object('host', 80).proxy?).to be true
|
554
|
+
|
555
|
+
disabled_req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :proxy => nil)
|
556
|
+
expect(disabled_req.net_http_object('host', 80).proxy?).to be_falsey
|
557
|
+
end
|
558
|
+
|
559
|
+
it "sets proxy on a per-request basis" do
|
560
|
+
expect(@proxy_req.net_http_object('some', 80).proxy?).to be_falsey
|
561
|
+
|
562
|
+
req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :proxy => 'http://example.com')
|
563
|
+
expect(req.net_http_object('host', 80).proxy?).to be true
|
564
|
+
end
|
565
|
+
|
566
|
+
it "overrides proxy from environment", if: RUBY_VERSION >= '2.0' do
|
567
|
+
allow(ENV).to receive(:[]).with("http_proxy").and_return("http://127.0.0.1")
|
568
|
+
allow(ENV).to receive(:[]).with("no_proxy").and_return(nil)
|
569
|
+
allow(ENV).to receive(:[]).with("NO_PROXY").and_return(nil)
|
570
|
+
allow(Netrc).to receive(:read).and_return({})
|
571
|
+
|
572
|
+
req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
|
573
|
+
obj = req.net_http_object('host', 80)
|
574
|
+
expect(obj.proxy?).to be true
|
575
|
+
expect(obj.proxy_address).to eq '127.0.0.1'
|
576
|
+
|
577
|
+
# test original method .proxy?
|
578
|
+
req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :proxy => nil)
|
579
|
+
obj = req.net_http_object('host', 80)
|
580
|
+
expect(obj.proxy?).to be_falsey
|
581
|
+
|
582
|
+
# stub RestClient.proxy_set? to peek into implementation
|
583
|
+
allow(RestClient).to receive(:proxy_set?).and_return(true)
|
584
|
+
req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
|
585
|
+
obj = req.net_http_object('host', 80)
|
586
|
+
expect(obj.proxy?).to be_falsey
|
587
|
+
|
588
|
+
# test stubbed Net::HTTP.new
|
589
|
+
req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :proxy => nil)
|
590
|
+
expect(Net::HTTP).to receive(:new).with('host', 80, nil, nil, nil, nil)
|
591
|
+
req.net_http_object('host', 80)
|
592
|
+
end
|
593
|
+
|
594
|
+
it "overrides global proxy with per-request proxy" do
|
595
|
+
allow(RestClient).to receive(:proxy).and_return('http://example.com')
|
596
|
+
allow(RestClient).to receive(:proxy_set?).and_return(true)
|
597
|
+
obj = @proxy_req.net_http_object('host', 80)
|
598
|
+
expect(obj.proxy?).to be true
|
599
|
+
expect(obj.proxy_address).to eq 'example.com'
|
600
|
+
|
601
|
+
req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :proxy => 'http://127.0.0.1/')
|
602
|
+
expect(req.net_http_object('host', 80).proxy?).to be true
|
603
|
+
expect(req.net_http_object('host', 80).proxy_address).to eq('127.0.0.1')
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
|
608
|
+
describe "logging" do
|
609
|
+
it "logs a get request" do
|
610
|
+
log = RestClient.log = []
|
611
|
+
RestClient::Request.new(:method => :get, :url => 'http://url', :headers => {:user_agent => 'rest-client'}).log_request
|
612
|
+
expect(log[0]).to eq %Q{RestClient.get "http://url", "Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", "User-Agent"=>"rest-client"\n}
|
613
|
+
end
|
614
|
+
|
615
|
+
it "logs a post request with a small payload" do
|
616
|
+
log = RestClient.log = []
|
617
|
+
RestClient::Request.new(:method => :post, :url => 'http://url', :payload => 'foo', :headers => {:user_agent => 'rest-client'}).log_request
|
618
|
+
expect(log[0]).to eq %Q{RestClient.post "http://url", "foo", "Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"3", "User-Agent"=>"rest-client"\n}
|
619
|
+
end
|
620
|
+
|
621
|
+
it "logs a post request with a large payload" do
|
622
|
+
log = RestClient.log = []
|
623
|
+
RestClient::Request.new(:method => :post, :url => 'http://url', :payload => ('x' * 1000), :headers => {:user_agent => 'rest-client'}).log_request
|
624
|
+
expect(log[0]).to eq %Q{RestClient.post "http://url", 1000 byte(s) length, "Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"1000", "User-Agent"=>"rest-client"\n}
|
625
|
+
end
|
626
|
+
|
627
|
+
it "logs input headers as a hash" do
|
628
|
+
log = RestClient.log = []
|
629
|
+
RestClient::Request.new(:method => :get, :url => 'http://url', :headers => { :accept => 'text/plain', :user_agent => 'rest-client' }).log_request
|
630
|
+
expect(log[0]).to eq %Q{RestClient.get "http://url", "Accept"=>"text/plain", "Accept-Encoding"=>"gzip, deflate", "User-Agent"=>"rest-client"\n}
|
631
|
+
end
|
632
|
+
|
633
|
+
it "logs a response including the status code, content type, and result body size in bytes" do
|
634
|
+
log = RestClient.log = []
|
635
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
|
636
|
+
allow(res).to receive(:[]).with('Content-type').and_return('text/html')
|
637
|
+
@request.log_response res
|
638
|
+
expect(log[0]).to eq "# => 200 OK | text/html 4 bytes\n"
|
639
|
+
end
|
640
|
+
|
641
|
+
it "logs a response with a nil Content-type" do
|
642
|
+
log = RestClient.log = []
|
643
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
|
644
|
+
allow(res).to receive(:[]).with('Content-type').and_return(nil)
|
645
|
+
@request.log_response res
|
646
|
+
expect(log[0]).to eq "# => 200 OK | 4 bytes\n"
|
647
|
+
end
|
648
|
+
|
649
|
+
it "logs a response with a nil body" do
|
650
|
+
log = RestClient.log = []
|
651
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => nil)
|
652
|
+
allow(res).to receive(:[]).with('Content-type').and_return('text/html; charset=utf-8')
|
653
|
+
@request.log_response res
|
654
|
+
expect(log[0]).to eq "# => 200 OK | text/html 0 bytes\n"
|
655
|
+
end
|
656
|
+
|
657
|
+
it 'does not log request password' do
|
658
|
+
log = RestClient.log = []
|
659
|
+
RestClient::Request.new(:method => :get, :url => 'http://user:password@url', :headers => {:user_agent => 'rest-client'}).log_request
|
660
|
+
expect(log[0]).to eq %Q{RestClient.get "http://user:REDACTED@url", "Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", "User-Agent"=>"rest-client"\n}
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
664
|
+
it "strips the charset from the response content type" do
|
665
|
+
log = RestClient.log = []
|
666
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
|
667
|
+
allow(res).to receive(:[]).with('Content-type').and_return('text/html; charset=utf-8')
|
668
|
+
@request.log_response res
|
669
|
+
expect(log[0]).to eq "# => 200 OK | text/html 4 bytes\n"
|
670
|
+
end
|
671
|
+
|
672
|
+
describe "timeout" do
|
673
|
+
it "does not set timeouts if not specified" do
|
674
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
|
675
|
+
allow(@http).to receive(:request)
|
676
|
+
allow(@request).to receive(:process_result)
|
677
|
+
allow(@request).to receive(:response_log)
|
678
|
+
|
679
|
+
expect(@net).not_to receive(:read_timeout=)
|
680
|
+
expect(@net).not_to receive(:open_timeout=)
|
681
|
+
|
682
|
+
@request.send(:transmit, @uri, 'req', nil)
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'sets read_timeout' do
|
686
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :read_timeout => 123)
|
687
|
+
allow(@http).to receive(:request)
|
688
|
+
allow(@request).to receive(:process_result)
|
689
|
+
allow(@request).to receive(:response_log)
|
690
|
+
|
691
|
+
expect(@net).to receive(:read_timeout=).with(123)
|
692
|
+
|
693
|
+
@request.send(:transmit, @uri, 'req', nil)
|
694
|
+
end
|
695
|
+
|
696
|
+
it "sets open_timeout" do
|
697
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :open_timeout => 123)
|
698
|
+
allow(@http).to receive(:request)
|
699
|
+
allow(@request).to receive(:process_result)
|
700
|
+
allow(@request).to receive(:response_log)
|
701
|
+
|
702
|
+
expect(@net).to receive(:open_timeout=).with(123)
|
703
|
+
|
704
|
+
@request.send(:transmit, @uri, 'req', nil)
|
705
|
+
end
|
706
|
+
|
707
|
+
it 'sets both timeouts with :timeout' do
|
708
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :timeout => 123)
|
709
|
+
allow(@http).to receive(:request)
|
710
|
+
allow(@request).to receive(:process_result)
|
711
|
+
allow(@request).to receive(:response_log)
|
712
|
+
|
713
|
+
expect(@net).to receive(:open_timeout=).with(123)
|
714
|
+
expect(@net).to receive(:read_timeout=).with(123)
|
715
|
+
|
716
|
+
@request.send(:transmit, @uri, 'req', nil)
|
717
|
+
end
|
718
|
+
|
719
|
+
it 'supersedes :timeout with open/read_timeout' do
|
720
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :timeout => 123, :open_timeout => 34, :read_timeout => 56)
|
721
|
+
allow(@http).to receive(:request)
|
722
|
+
allow(@request).to receive(:process_result)
|
723
|
+
allow(@request).to receive(:response_log)
|
724
|
+
|
725
|
+
expect(@net).to receive(:open_timeout=).with(34)
|
726
|
+
expect(@net).to receive(:read_timeout=).with(56)
|
727
|
+
|
728
|
+
@request.send(:transmit, @uri, 'req', nil)
|
729
|
+
end
|
730
|
+
|
731
|
+
|
732
|
+
it "disable timeout by setting it to nil" do
|
733
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :read_timeout => nil, :open_timeout => nil)
|
734
|
+
allow(@http).to receive(:request)
|
735
|
+
allow(@request).to receive(:process_result)
|
736
|
+
allow(@request).to receive(:response_log)
|
737
|
+
|
738
|
+
expect(@net).to receive(:read_timeout=).with(nil)
|
739
|
+
expect(@net).to receive(:open_timeout=).with(nil)
|
740
|
+
|
741
|
+
@request.send(:transmit, @uri, 'req', nil)
|
742
|
+
end
|
743
|
+
|
744
|
+
it 'deprecated: warns when disabling timeout by setting it to -1' do
|
745
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :read_timeout => -1)
|
746
|
+
allow(@http).to receive(:request)
|
747
|
+
allow(@request).to receive(:process_result)
|
748
|
+
allow(@request).to receive(:response_log)
|
749
|
+
|
750
|
+
expect(@net).to receive(:read_timeout=).with(nil)
|
751
|
+
|
752
|
+
expect(fake_stderr {
|
753
|
+
@request.send(:transmit, @uri, 'req', nil)
|
754
|
+
}).to match(/^Deprecated: .*timeout.* nil instead of -1$/)
|
755
|
+
end
|
756
|
+
|
757
|
+
it "deprecated: disable timeout by setting it to -1" do
|
758
|
+
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :read_timeout => -1, :open_timeout => -1)
|
759
|
+
allow(@http).to receive(:request)
|
760
|
+
allow(@request).to receive(:process_result)
|
761
|
+
allow(@request).to receive(:response_log)
|
762
|
+
|
763
|
+
expect(@request).to receive(:warn)
|
764
|
+
expect(@net).to receive(:read_timeout=).with(nil)
|
765
|
+
|
766
|
+
expect(@request).to receive(:warn)
|
767
|
+
expect(@net).to receive(:open_timeout=).with(nil)
|
768
|
+
|
769
|
+
@request.send(:transmit, @uri, 'req', nil)
|
770
|
+
end
|
771
|
+
end
|
772
|
+
|
773
|
+
describe "ssl" do
|
774
|
+
it "uses SSL when the URI refers to a https address" do
|
775
|
+
allow(@uri).to receive(:is_a?).with(URI::HTTPS).and_return(true)
|
776
|
+
expect(@net).to receive(:use_ssl=).with(true)
|
777
|
+
allow(@http).to receive(:request)
|
778
|
+
allow(@request).to receive(:process_result)
|
779
|
+
allow(@request).to receive(:response_log)
|
780
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
781
|
+
end
|
782
|
+
|
783
|
+
it "should default to verifying ssl certificates" do
|
784
|
+
expect(@request.verify_ssl).to eq OpenSSL::SSL::VERIFY_PEER
|
785
|
+
end
|
786
|
+
|
787
|
+
it "should have expected values for VERIFY_PEER and VERIFY_NONE" do
|
788
|
+
expect(OpenSSL::SSL::VERIFY_NONE).to eq(0)
|
789
|
+
expect(OpenSSL::SSL::VERIFY_PEER).to eq(1)
|
790
|
+
end
|
791
|
+
|
792
|
+
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is false" do
|
793
|
+
@request = RestClient::Request.new(:method => :put, :verify_ssl => false, :url => 'http://some/resource', :payload => 'payload')
|
794
|
+
expect(@net).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
795
|
+
allow(@http).to receive(:request)
|
796
|
+
allow(@request).to receive(:process_result)
|
797
|
+
allow(@request).to receive(:response_log)
|
798
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
799
|
+
end
|
800
|
+
|
801
|
+
it "should not set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is true" do
|
802
|
+
@request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload', :verify_ssl => true)
|
803
|
+
expect(@net).not_to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
804
|
+
allow(@http).to receive(:request)
|
805
|
+
allow(@request).to receive(:process_result)
|
806
|
+
allow(@request).to receive(:response_log)
|
807
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
808
|
+
end
|
809
|
+
|
810
|
+
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_PEER if verify_ssl is true" do
|
811
|
+
@request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload', :verify_ssl => true)
|
812
|
+
expect(@net).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
813
|
+
allow(@http).to receive(:request)
|
814
|
+
allow(@request).to receive(:process_result)
|
815
|
+
allow(@request).to receive(:response_log)
|
816
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
817
|
+
end
|
818
|
+
|
819
|
+
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_PEER if verify_ssl is not given" do
|
820
|
+
@request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload')
|
821
|
+
expect(@net).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
822
|
+
allow(@http).to receive(:request)
|
823
|
+
allow(@request).to receive(:process_result)
|
824
|
+
allow(@request).to receive(:response_log)
|
825
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
826
|
+
end
|
827
|
+
|
828
|
+
it "should set net.verify_mode to the passed value if verify_ssl is an OpenSSL constant" do
|
829
|
+
mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
830
|
+
@request = RestClient::Request.new( :method => :put,
|
831
|
+
:url => 'https://some/resource',
|
832
|
+
:payload => 'payload',
|
833
|
+
:verify_ssl => mode )
|
834
|
+
expect(@net).to receive(:verify_mode=).with(mode)
|
835
|
+
allow(@http).to receive(:request)
|
836
|
+
allow(@request).to receive(:process_result)
|
837
|
+
allow(@request).to receive(:response_log)
|
838
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
839
|
+
end
|
840
|
+
|
841
|
+
it "should default to not having an ssl_client_cert" do
|
842
|
+
expect(@request.ssl_client_cert).to be(nil)
|
843
|
+
end
|
844
|
+
|
845
|
+
it "should set the ssl_version if provided" do
|
846
|
+
@request = RestClient::Request.new(
|
847
|
+
:method => :put,
|
848
|
+
:url => 'https://some/resource',
|
849
|
+
:payload => 'payload',
|
850
|
+
:ssl_version => "TLSv1"
|
851
|
+
)
|
852
|
+
expect(@net).to receive(:ssl_version=).with("TLSv1")
|
853
|
+
allow(@http).to receive(:request)
|
854
|
+
allow(@request).to receive(:process_result)
|
855
|
+
allow(@request).to receive(:response_log)
|
856
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
857
|
+
end
|
858
|
+
|
859
|
+
it "should not set the ssl_version if not provided" do
|
860
|
+
@request = RestClient::Request.new(
|
861
|
+
:method => :put,
|
862
|
+
:url => 'https://some/resource',
|
863
|
+
:payload => 'payload'
|
864
|
+
)
|
865
|
+
expect(@net).not_to receive(:ssl_version=).with("TLSv1")
|
866
|
+
allow(@http).to receive(:request)
|
867
|
+
allow(@request).to receive(:process_result)
|
868
|
+
allow(@request).to receive(:response_log)
|
869
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
870
|
+
end
|
871
|
+
|
872
|
+
it "should set the ssl_ciphers if provided" do
|
873
|
+
ciphers = 'AESGCM:HIGH:!aNULL:!eNULL:RC4+RSA'
|
874
|
+
@request = RestClient::Request.new(
|
875
|
+
:method => :put,
|
876
|
+
:url => 'https://some/resource',
|
877
|
+
:payload => 'payload',
|
878
|
+
:ssl_ciphers => ciphers
|
879
|
+
)
|
880
|
+
expect(@net).to receive(:ciphers=).with(ciphers)
|
881
|
+
allow(@http).to receive(:request)
|
882
|
+
allow(@request).to receive(:process_result)
|
883
|
+
allow(@request).to receive(:response_log)
|
884
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
885
|
+
end
|
886
|
+
|
887
|
+
it "should not set the ssl_ciphers if set to nil" do
|
888
|
+
@request = RestClient::Request.new(
|
889
|
+
:method => :put,
|
890
|
+
:url => 'https://some/resource',
|
891
|
+
:payload => 'payload',
|
892
|
+
:ssl_ciphers => nil,
|
893
|
+
)
|
894
|
+
expect(@net).not_to receive(:ciphers=)
|
895
|
+
allow(@http).to receive(:request)
|
896
|
+
allow(@request).to receive(:process_result)
|
897
|
+
allow(@request).to receive(:response_log)
|
898
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
899
|
+
end
|
900
|
+
|
901
|
+
it "should override ssl_ciphers with better defaults with weak default ciphers" do
|
902
|
+
stub_const(
|
903
|
+
'::OpenSSL::SSL::SSLContext::DEFAULT_PARAMS',
|
904
|
+
{
|
905
|
+
:ssl_version=>"SSLv23",
|
906
|
+
:verify_mode=>1,
|
907
|
+
:ciphers=>"ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW",
|
908
|
+
:options=>-2147480577,
|
909
|
+
}
|
910
|
+
)
|
911
|
+
|
912
|
+
@request = RestClient::Request.new(
|
913
|
+
:method => :put,
|
914
|
+
:url => 'https://some/resource',
|
915
|
+
:payload => 'payload',
|
916
|
+
)
|
917
|
+
|
918
|
+
expect(@net).to receive(:ciphers=).with(RestClient::Request::DefaultCiphers)
|
919
|
+
|
920
|
+
allow(@http).to receive(:request)
|
921
|
+
allow(@request).to receive(:process_result)
|
922
|
+
allow(@request).to receive(:response_log)
|
923
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
924
|
+
end
|
925
|
+
|
926
|
+
it "should not override ssl_ciphers with better defaults with different default ciphers" do
|
927
|
+
stub_const(
|
928
|
+
'::OpenSSL::SSL::SSLContext::DEFAULT_PARAMS',
|
929
|
+
{
|
930
|
+
:ssl_version=>"SSLv23",
|
931
|
+
:verify_mode=>1,
|
932
|
+
:ciphers=>"HIGH:!aNULL:!eNULL:!EXPORT:!LOW:!MEDIUM:!SSLv2",
|
933
|
+
:options=>-2147480577,
|
934
|
+
}
|
935
|
+
)
|
936
|
+
|
937
|
+
@request = RestClient::Request.new(
|
938
|
+
:method => :put,
|
939
|
+
:url => 'https://some/resource',
|
940
|
+
:payload => 'payload',
|
941
|
+
)
|
942
|
+
|
943
|
+
expect(@net).not_to receive(:ciphers=)
|
944
|
+
|
945
|
+
allow(@http).to receive(:request)
|
946
|
+
allow(@request).to receive(:process_result)
|
947
|
+
allow(@request).to receive(:response_log)
|
948
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
949
|
+
end
|
950
|
+
|
951
|
+
it "should set the ssl_client_cert if provided" do
|
952
|
+
@request = RestClient::Request.new(
|
953
|
+
:method => :put,
|
954
|
+
:url => 'https://some/resource',
|
955
|
+
:payload => 'payload',
|
956
|
+
:ssl_client_cert => "whatsupdoc!"
|
957
|
+
)
|
958
|
+
expect(@net).to receive(:cert=).with("whatsupdoc!")
|
959
|
+
allow(@http).to receive(:request)
|
960
|
+
allow(@request).to receive(:process_result)
|
961
|
+
allow(@request).to receive(:response_log)
|
962
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
963
|
+
end
|
964
|
+
|
965
|
+
it "should not set the ssl_client_cert if it is not provided" do
|
966
|
+
@request = RestClient::Request.new(
|
967
|
+
:method => :put,
|
968
|
+
:url => 'https://some/resource',
|
969
|
+
:payload => 'payload'
|
970
|
+
)
|
971
|
+
expect(@net).not_to receive(:cert=)
|
972
|
+
allow(@http).to receive(:request)
|
973
|
+
allow(@request).to receive(:process_result)
|
974
|
+
allow(@request).to receive(:response_log)
|
975
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
976
|
+
end
|
977
|
+
|
978
|
+
it "should default to not having an ssl_client_key" do
|
979
|
+
expect(@request.ssl_client_key).to be(nil)
|
980
|
+
end
|
981
|
+
|
982
|
+
it "should set the ssl_client_key if provided" do
|
983
|
+
@request = RestClient::Request.new(
|
984
|
+
:method => :put,
|
985
|
+
:url => 'https://some/resource',
|
986
|
+
:payload => 'payload',
|
987
|
+
:ssl_client_key => "whatsupdoc!"
|
988
|
+
)
|
989
|
+
expect(@net).to receive(:key=).with("whatsupdoc!")
|
990
|
+
allow(@http).to receive(:request)
|
991
|
+
allow(@request).to receive(:process_result)
|
992
|
+
allow(@request).to receive(:response_log)
|
993
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
994
|
+
end
|
995
|
+
|
996
|
+
it "should not set the ssl_client_key if it is not provided" do
|
997
|
+
@request = RestClient::Request.new(
|
998
|
+
:method => :put,
|
999
|
+
:url => 'https://some/resource',
|
1000
|
+
:payload => 'payload'
|
1001
|
+
)
|
1002
|
+
expect(@net).not_to receive(:key=)
|
1003
|
+
allow(@http).to receive(:request)
|
1004
|
+
allow(@request).to receive(:process_result)
|
1005
|
+
allow(@request).to receive(:response_log)
|
1006
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
it "should default to not having an ssl_ca_file" do
|
1010
|
+
expect(@request.ssl_ca_file).to be(nil)
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
it "should set the ssl_ca_file if provided" do
|
1014
|
+
@request = RestClient::Request.new(
|
1015
|
+
:method => :put,
|
1016
|
+
:url => 'https://some/resource',
|
1017
|
+
:payload => 'payload',
|
1018
|
+
:ssl_ca_file => "Certificate Authority File"
|
1019
|
+
)
|
1020
|
+
expect(@net).to receive(:ca_file=).with("Certificate Authority File")
|
1021
|
+
expect(@net).not_to receive(:cert_store=)
|
1022
|
+
allow(@http).to receive(:request)
|
1023
|
+
allow(@request).to receive(:process_result)
|
1024
|
+
allow(@request).to receive(:response_log)
|
1025
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1026
|
+
end
|
1027
|
+
|
1028
|
+
it "should not set the ssl_ca_file if it is not provided" do
|
1029
|
+
@request = RestClient::Request.new(
|
1030
|
+
:method => :put,
|
1031
|
+
:url => 'https://some/resource',
|
1032
|
+
:payload => 'payload'
|
1033
|
+
)
|
1034
|
+
expect(@net).not_to receive(:ca_file=)
|
1035
|
+
allow(@http).to receive(:request)
|
1036
|
+
allow(@request).to receive(:process_result)
|
1037
|
+
allow(@request).to receive(:response_log)
|
1038
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
it "should default to not having an ssl_ca_path" do
|
1042
|
+
expect(@request.ssl_ca_path).to be(nil)
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
it "should set the ssl_ca_path if provided" do
|
1046
|
+
@request = RestClient::Request.new(
|
1047
|
+
:method => :put,
|
1048
|
+
:url => 'https://some/resource',
|
1049
|
+
:payload => 'payload',
|
1050
|
+
:ssl_ca_path => "Certificate Authority Path"
|
1051
|
+
)
|
1052
|
+
expect(@net).to receive(:ca_path=).with("Certificate Authority Path")
|
1053
|
+
expect(@net).not_to receive(:cert_store=)
|
1054
|
+
allow(@http).to receive(:request)
|
1055
|
+
allow(@request).to receive(:process_result)
|
1056
|
+
allow(@request).to receive(:response_log)
|
1057
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
it "should not set the ssl_ca_path if it is not provided" do
|
1061
|
+
@request = RestClient::Request.new(
|
1062
|
+
:method => :put,
|
1063
|
+
:url => 'https://some/resource',
|
1064
|
+
:payload => 'payload'
|
1065
|
+
)
|
1066
|
+
expect(@net).not_to receive(:ca_path=)
|
1067
|
+
allow(@http).to receive(:request)
|
1068
|
+
allow(@request).to receive(:process_result)
|
1069
|
+
allow(@request).to receive(:response_log)
|
1070
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
it "should set the ssl_cert_store if provided" do
|
1074
|
+
store = OpenSSL::X509::Store.new
|
1075
|
+
store.set_default_paths
|
1076
|
+
|
1077
|
+
@request = RestClient::Request.new(
|
1078
|
+
:method => :put,
|
1079
|
+
:url => 'https://some/resource',
|
1080
|
+
:payload => 'payload',
|
1081
|
+
:ssl_cert_store => store
|
1082
|
+
)
|
1083
|
+
expect(@net).to receive(:cert_store=).with(store)
|
1084
|
+
expect(@net).not_to receive(:ca_path=)
|
1085
|
+
expect(@net).not_to receive(:ca_file=)
|
1086
|
+
allow(@http).to receive(:request)
|
1087
|
+
allow(@request).to receive(:process_result)
|
1088
|
+
allow(@request).to receive(:response_log)
|
1089
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
it "should by default set the ssl_cert_store if no CA info is provided" do
|
1093
|
+
@request = RestClient::Request.new(
|
1094
|
+
:method => :put,
|
1095
|
+
:url => 'https://some/resource',
|
1096
|
+
:payload => 'payload'
|
1097
|
+
)
|
1098
|
+
expect(@net).to receive(:cert_store=)
|
1099
|
+
expect(@net).not_to receive(:ca_path=)
|
1100
|
+
expect(@net).not_to receive(:ca_file=)
|
1101
|
+
allow(@http).to receive(:request)
|
1102
|
+
allow(@request).to receive(:process_result)
|
1103
|
+
allow(@request).to receive(:response_log)
|
1104
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
it "should not set the ssl_cert_store if it is set falsy" do
|
1108
|
+
@request = RestClient::Request.new(
|
1109
|
+
:method => :put,
|
1110
|
+
:url => 'https://some/resource',
|
1111
|
+
:payload => 'payload',
|
1112
|
+
:ssl_cert_store => nil,
|
1113
|
+
)
|
1114
|
+
expect(@net).not_to receive(:cert_store=)
|
1115
|
+
allow(@http).to receive(:request)
|
1116
|
+
allow(@request).to receive(:process_result)
|
1117
|
+
allow(@request).to receive(:response_log)
|
1118
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
it "should not set the ssl_verify_callback by default" do
|
1122
|
+
@request = RestClient::Request.new(
|
1123
|
+
:method => :put,
|
1124
|
+
:url => 'https://some/resource',
|
1125
|
+
:payload => 'payload',
|
1126
|
+
)
|
1127
|
+
expect(@net).not_to receive(:verify_callback=)
|
1128
|
+
allow(@http).to receive(:request)
|
1129
|
+
allow(@request).to receive(:process_result)
|
1130
|
+
allow(@request).to receive(:response_log)
|
1131
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
it "should set the ssl_verify_callback if passed" do
|
1135
|
+
callback = lambda {}
|
1136
|
+
@request = RestClient::Request.new(
|
1137
|
+
:method => :put,
|
1138
|
+
:url => 'https://some/resource',
|
1139
|
+
:payload => 'payload',
|
1140
|
+
:ssl_verify_callback => callback,
|
1141
|
+
)
|
1142
|
+
expect(@net).to receive(:verify_callback=).with(callback)
|
1143
|
+
|
1144
|
+
# we'll read cert_store on jruby
|
1145
|
+
# https://github.com/jruby/jruby/issues/597
|
1146
|
+
if RestClient::Platform.jruby?
|
1147
|
+
allow(@net).to receive(:cert_store)
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
allow(@http).to receive(:request)
|
1151
|
+
allow(@request).to receive(:process_result)
|
1152
|
+
allow(@request).to receive(:response_log)
|
1153
|
+
@request.send(:transmit, @uri, 'req', 'payload')
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
# </ssl>
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
it "should still return a response object for 204 No Content responses" do
|
1160
|
+
@request = RestClient::Request.new(
|
1161
|
+
:method => :put,
|
1162
|
+
:url => 'https://some/resource',
|
1163
|
+
:payload => 'payload'
|
1164
|
+
)
|
1165
|
+
net_http_res = Net::HTTPNoContent.new("", "204", "No Content")
|
1166
|
+
allow(net_http_res).to receive(:read_body).and_return(nil)
|
1167
|
+
expect(@http).to receive(:request).and_return(@request.send(:fetch_body, net_http_res))
|
1168
|
+
response = @request.send(:transmit, @uri, 'req', 'payload')
|
1169
|
+
expect(response).not_to be_nil
|
1170
|
+
expect(response.code).to eq 204
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
describe "raw response" do
|
1174
|
+
it "should read the response into a binary-mode tempfile" do
|
1175
|
+
@request = RestClient::Request.new(:method => "get", :url => "example.com", :raw_response => true)
|
1176
|
+
|
1177
|
+
tempfile = double("tempfile")
|
1178
|
+
expect(tempfile).to receive(:binmode)
|
1179
|
+
allow(tempfile).to receive(:open)
|
1180
|
+
allow(tempfile).to receive(:close)
|
1181
|
+
expect(Tempfile).to receive(:new).with("rest-client.").and_return(tempfile)
|
1182
|
+
|
1183
|
+
net_http_res = Net::HTTPOK.new(nil, "200", "body")
|
1184
|
+
allow(net_http_res).to receive(:read_body).and_return("body")
|
1185
|
+
@request.send(:fetch_body, net_http_res)
|
1186
|
+
end
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
describe 'payloads' do
|
1190
|
+
it 'should accept string payloads' do
|
1191
|
+
payload = 'Foo'
|
1192
|
+
@request = RestClient::Request.new(method: :get, url: 'example.com', :payload => payload)
|
1193
|
+
expect(@request).to receive(:process_result)
|
1194
|
+
expect(@http).to receive(:request).with('req', payload)
|
1195
|
+
@request.send(:transmit, @uri, 'req', payload)
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
it 'should accept streaming IO payloads' do
|
1199
|
+
payload = StringIO.new('streamed')
|
1200
|
+
|
1201
|
+
@request = RestClient::Request.new(method: :get, url: 'example.com', :payload => payload)
|
1202
|
+
expect(@request).to receive(:process_result)
|
1203
|
+
|
1204
|
+
@get = double('net::http::get')
|
1205
|
+
expect(@get).to receive(:body_stream=).with(instance_of(RestClient::Payload::Streamed))
|
1206
|
+
|
1207
|
+
allow(@request.net_http_request_class(:GET)).to receive(:new).and_return(@get)
|
1208
|
+
expect(@http).to receive(:request).with(@get, nil)
|
1209
|
+
@request.execute
|
1210
|
+
end
|
1211
|
+
end
|
1212
|
+
|
1213
|
+
describe 'constructor' do
|
1214
|
+
it 'should reject valid URIs with no hostname' do
|
1215
|
+
expect(URI.parse('http:///').hostname).to be_nil
|
1216
|
+
|
1217
|
+
expect {
|
1218
|
+
RestClient::Request.new(method: :get, url: 'http:///')
|
1219
|
+
}.to raise_error(URI::InvalidURIError, /\Abad URI/)
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
it 'should reject invalid URIs' do
|
1223
|
+
expect {
|
1224
|
+
RestClient::Request.new(method: :get, url: 'http://::')
|
1225
|
+
}.to raise_error(URI::InvalidURIError)
|
1226
|
+
end
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
describe 'process_url_params' do
|
1230
|
+
it 'should handle basic URL params' do
|
1231
|
+
expect(@request.process_url_params('https://example.com/foo', params: {key1: 123, key2: 'abc'})).
|
1232
|
+
to eq 'https://example.com/foo?key1=123&key2=abc'
|
1233
|
+
|
1234
|
+
expect(@request.process_url_params('https://example.com/foo', params: {'key1' => 123})).
|
1235
|
+
to eq 'https://example.com/foo?key1=123'
|
1236
|
+
|
1237
|
+
expect(@request.process_url_params('https://example.com/path',
|
1238
|
+
params: {foo: 'one two', bar: 'three + four == seven'})).
|
1239
|
+
to eq 'https://example.com/path?foo=one+two&bar=three+%2B+four+%3D%3D+seven'
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
it 'should combine with & when URL params already exist' do
|
1243
|
+
expect(@request.process_url_params('https://example.com/path?foo=1', params: {bar: 2})).
|
1244
|
+
to eq 'https://example.com/path?foo=1&bar=2'
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
it 'should handle complex nested URL params per Rack / Rails conventions' do
|
1248
|
+
expect(@request.process_url_params('https://example.com/', params: {
|
1249
|
+
foo: [1,2,3],
|
1250
|
+
null: nil,
|
1251
|
+
false: false,
|
1252
|
+
math: '2+2=4',
|
1253
|
+
nested: {'key + escaped' => 'value + escaped', other: [], arr: [1,2]},
|
1254
|
+
})).to eq 'https://example.com/?foo[]=1&foo[]=2&foo[]=3&null&false=false&math=2%2B2%3D4' \
|
1255
|
+
'&nested[key+%2B+escaped]=value+%2B+escaped&nested[other]' \
|
1256
|
+
'&nested[arr][]=1&nested[arr][]=2'
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it 'should handle ParamsArray objects' do
|
1260
|
+
expect(@request.process_url_params('https://example.com/',
|
1261
|
+
params: RestClient::ParamsArray.new([[:foo, 1], [:foo, 2]])
|
1262
|
+
)).to eq 'https://example.com/?foo=1&foo=2'
|
1263
|
+
end
|
1264
|
+
end
|
1265
|
+
end
|