summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2014-11-13 12:41:20 +0000
committerLamont Granquist <lamont@scriptkiddie.org>2015-01-25 13:27:02 -0800
commit508f14aec1f6e4b02233f4deefa3b93f019c59a4 (patch)
treec71bd3c73d08ca1aec5c642cb10a95b55c52d092 /spec/unit
parent008e33f7f458562f1a390413800afbbd07c2cf3a (diff)
downloadchef-508f14aec1f6e4b02233f4deefa3b93f019c59a4.tar.gz
Add --proxy-auth option to `knife raw`
Chef Server 12 and Enterprise Chef Server allow requests made on behalf of other users by setting the x-ops-request-source HTTP header to web and signing the request with a particular key (often known as the "webui key"). This scheme allows the management console to make requests to the API on behalf of the logged in user. However, it is also useful for administrators attempting to debug their Chef Servers or helping their users in large Chef Server installations. For example, using the webui_key and this option, an adminstrator can list nodes in different orgs, without access to a particular user's key. > knife raw /organizations/wonderbolts/nodes -k webui_priv.pem \ -u soarin -s https://api.opscode.piab --proxy-auth { } > knife raw /organizations/acme/nodes -k webui_priv.pem -u wei -s https://api.opscode.piab --proxy-auth { } The webui key exists on the Chef Server itself and is only accessible to an administrator with root access. As such, this is typically an advanced debugging tool and isn't likely needed in other knife subcommands.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/knife/raw_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/unit/knife/raw_spec.rb b/spec/unit/knife/raw_spec.rb
new file mode 100644
index 0000000000..547ddee992
--- /dev/null
+++ b/spec/unit/knife/raw_spec.rb
@@ -0,0 +1,38 @@
+#
+# Author:: Steven Danna (<steve@getchef.com>)
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+describe Chef::Knife::Raw do
+ before(:each) do
+ @rest = double('Chef::Knife::Raw::RawInputServerAPI')
+ allow(Chef::Knife::Raw::RawInputServerAPI).to receive(:new).and_return(@rest)
+ @knife = Chef::Knife::Raw.new
+ @knife.config[:method] = "GET"
+ @knife.name_args = [ "/nodes" ]
+ end
+
+ describe "run" do
+ it "should set the x-ops-request-source header when --proxy-auth is set" do
+ @knife.config[:proxy_auth] = true
+ expect(@rest).to receive(:request).with(:GET, "/nodes",
+ { 'Content-Type' => 'application/json',
+ 'x-ops-request-source' => 'web'}, false)
+ @knife.run
+ end
+ end
+end