summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnehaldwivedi <sdwivedi@msystechnologies.com>2020-08-06 06:36:57 -0700
committersnehaldwivedi <sdwivedi@msystechnologies.com>2021-02-16 02:45:13 -0800
commitc9080be779d38478960425b53afc08fd52a96562 (patch)
tree2c0a64df18d77d957b5aceebd8636ae16ac3c198
parent43c05d73aa15b1d5148ccacf36e2f6def5c814e4 (diff)
downloadchef-c9080be779d38478960425b53afc08fd52a96562.tar.gz
Updated reviewed changes for copyrights and roo_rest
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
-rw-r--r--lib/chef/group.rb2
-rw-r--r--lib/chef/knife/org_create.rb2
-rw-r--r--lib/chef/knife/org_delete.rb10
-rw-r--r--lib/chef/knife/org_edit.rb5
-rw-r--r--lib/chef/knife/org_list.rb10
-rw-r--r--lib/chef/knife/org_show.rb10
-rw-r--r--lib/chef/knife/org_user_add.rb2
-rw-r--r--lib/chef/knife/org_user_remove.rb2
-rw-r--r--lib/chef/knife/user_create.rb11
-rw-r--r--lib/chef/knife/user_delete.rb13
-rw-r--r--lib/chef/knife/user_edit.rb7
-rw-r--r--lib/chef/knife/user_list.rb13
-rw-r--r--lib/chef/knife/user_password.rb19
-rw-r--r--lib/chef/knife/user_show.rb15
-rw-r--r--lib/chef/mixin/root_rest.rb31
-rw-r--r--lib/chef/org/group_operations.rb.old60
-rw-r--r--spec/unit/knife/org_delete_spec.rb18
-rw-r--r--spec/unit/knife/org_list_spec.rb12
-rw-r--r--spec/unit/knife/org_show_spec.rb19
-rw-r--r--spec/unit/knife/org_user_add_spec.rb2
-rw-r--r--spec/unit/knife/user_create_spec.rb46
-rw-r--r--spec/unit/knife/user_delete_spec.rb4
-rw-r--r--spec/unit/knife/user_edit_spec.rb2
-rw-r--r--spec/unit/knife/user_list_spec.rb2
-rw-r--r--spec/unit/knife/user_password_spec.rb18
-rw-r--r--spec/unit/knife/user_show_spec.rb30
26 files changed, 148 insertions, 217 deletions
diff --git a/lib/chef/group.rb b/lib/chef/group.rb
index d1b4f1ac01..72f5b7b474 100644
--- a/lib/chef/group.rb
+++ b/lib/chef/group.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/knife/org_create.rb b/lib/chef/knife/org_create.rb
index 0eba7ccda6..d9f30e565d 100644
--- a/lib/chef/knife/org_create.rb
+++ b/lib/chef/knife/org_create.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/knife/org_delete.rb b/lib/chef/knife/org_delete.rb
index d6748f7b21..6fc3f7aaae 100644
--- a/lib/chef/knife/org_delete.rb
+++ b/lib/chef/knife/org_delete.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -23,12 +22,15 @@ class Chef
category "CHEF ORGANIZATION MANAGEMENT"
banner "knife org delete ORG_NAME"
- include Chef::Mixin::RootRestv0
+ deps do
+ require_relative "../org"
+ end
def run
org_name = @name_args[0]
+ org = Chef::Org.new(org_name)
ui.confirm "Do you want to delete the organization #{org_name}"
- ui.output root_rest.delete("organizations/#{org_name}")
+ ui.output org.chef_rest.delete("organizations/#{org_name}")
end
end
end
diff --git a/lib/chef/knife/org_edit.rb b/lib/chef/knife/org_edit.rb
index 54bbaaede6..f35262181b 100644
--- a/lib/chef/knife/org_edit.rb
+++ b/lib/chef/knife/org_edit.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -32,8 +31,6 @@ class Chef
exit 1
end
- include Chef::Mixin::RootRestv0
-
original_org = root_rest.get("organizations/#{org_name}")
edited_org = edit_data(original_org)
diff --git a/lib/chef/knife/org_list.rb b/lib/chef/knife/org_list.rb
index 1138743abe..33c7b4c893 100644
--- a/lib/chef/knife/org_list.rb
+++ b/lib/chef/knife/org_list.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -33,10 +32,13 @@ class Chef
short: "-a",
description: "Show auto-generated hidden orgs in output"
- include Chef::Mixin::RootRestv0
+ deps do
+ require_relative "../org"
+ end
def run
- results = root_rest.get("organizations")
+ org = Chef::Org.from_hash({})
+ results = org.chef_rest.get("organizations")
unless config[:all_orgs]
results = results.select { |k, v| !(k.length == 20 && k =~ /^[a-z]+$/) }
end
diff --git a/lib/chef/knife/org_show.rb b/lib/chef/knife/org_show.rb
index 035658ad47..d96dfb7727 100644
--- a/lib/chef/knife/org_show.rb
+++ b/lib/chef/knife/org_show.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -23,11 +22,14 @@ class Chef
category "CHEF ORGANIZATION MANAGEMENT"
banner "knife org show ORGNAME"
- include Chef::Mixin::RootRestv0
+ deps do
+ require_relative "../org"
+ end
def run
org_name = @name_args[0]
- ui.output root_rest.get("organizations/#{org_name}")
+ org = Chef::Org.from_hash({ "name" => org_name })
+ ui.output org.chef_rest.get("organizations/#{org_name}")
end
end
end
diff --git a/lib/chef/knife/org_user_add.rb b/lib/chef/knife/org_user_add.rb
index 550bb77f4d..cd0ea88d56 100644
--- a/lib/chef/knife/org_user_add.rb
+++ b/lib/chef/knife/org_user_add.rb
@@ -1,6 +1,6 @@
#
# Author:: Marc Paradise (<marc@chef.io>)
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/knife/org_user_remove.rb b/lib/chef/knife/org_user_remove.rb
index f9fa49611c..50a1471443 100644
--- a/lib/chef/knife/org_user_remove.rb
+++ b/lib/chef/knife/org_user_remove.rb
@@ -1,6 +1,6 @@
#
# Author:: Marc Paradise (<marc@getchef.com>)
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/knife/user_create.rb b/lib/chef/knife/user_create.rb
index 0c7f31b604..471fc24bd8 100644
--- a/lib/chef/knife/user_create.rb
+++ b/lib/chef/knife/user_create.rb
@@ -1,7 +1,7 @@
#
# Author:: Steven Danna (<steve@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
# limitations under the License.
#
-require_relative "../mixin/root_rest"
require_relative "../knife"
require "chef-utils/dist" unless defined?(ChefUtils::Dist)
@@ -25,8 +24,6 @@ class Chef
class Knife
class UserCreate < Knife
- include Chef::Mixin::RootRestv0
-
attr_accessor :user_field
deps do
@@ -122,13 +119,13 @@ class Chef
end
end
- final_user = root_rest.post("users/", user_hash)
+ final_user = user.chef_root_rest_v0.post("users/", user_hash)
if config[:orgname]
request_body = { user: user.username }
- response = root_rest.post("organizations/#{config[:orgname]}/association_requests", request_body)
+ response = user.chef_root_rest_v0.post("organizations/#{config[:orgname]}/association_requests", request_body)
association_id = response["uri"].split("/").last
- root_rest.put("users/#{user.username}/association_requests/#{association_id}", { response: "accept" })
+ user.chef_root_rest_v0.put("users/#{user.username}/association_requests/#{association_id}", { response: "accept" })
end
ui.info("Created #{user}")
diff --git a/lib/chef/knife/user_delete.rb b/lib/chef/knife/user_delete.rb
index 7ddc0871ae..217b83e2fa 100644
--- a/lib/chef/knife/user_delete.rb
+++ b/lib/chef/knife/user_delete.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
#
require_relative "../knife"
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -25,6 +24,7 @@ class Chef
deps do
require_relative "../org"
+ require_relative "../user_v1"
end
banner "knife user delete USER (options)"
@@ -40,7 +40,10 @@ class Chef
description: "If the user is a member of any org admin groups, attempt to remove from those groups. Ignored if --no-disassociate-user is set."
attr_reader :username
- include Chef::Mixin::RootRestv0
+
+ def user
+ @user_field ||= Chef::UserV1.new
+ end
def run
@username = @name_args[0]
@@ -84,7 +87,7 @@ class Chef
end
def org_memberships(username)
- org_data = root_rest.get("users/#{username}/organizations")
+ org_data = user.chef_root_rest_v0.get("users/#{username}/organizations")
org_data.map { |org| Chef::Org.new(org["organization"]["name"]) }
end
@@ -111,7 +114,7 @@ class Chef
def delete_user(username)
ui.stderr.puts "Deleting user #{username}."
- root_rest.delete("users/#{username}")
+ user.chef_root_rest_v0.delete("users/#{username}")
end
# Error message that says how to removed from org
diff --git a/lib/chef/knife/user_edit.rb b/lib/chef/knife/user_edit.rb
index 3ff23bbad5..6175276335 100644
--- a/lib/chef/knife/user_edit.rb
+++ b/lib/chef/knife/user_edit.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,8 +38,6 @@ class Chef
short: "-f FILENAME",
description: "Write private key to FILENAME rather than STDOUT"
- include Chef::Mixin::RootRestv0
-
def run
@user_name = @name_args[0]
@@ -52,8 +50,7 @@ class Chef
original_user = Chef::UserV1.load(@user_name).to_hash
edited_user = edit_hash(original_user)
if original_user != edited_user
- # user = Chef::UserV1.from_hash(edited_user)
- result = root_rest.put("users/#{@user_name}", edited_user)
+ result = Chef::UserV1.new.chef_root_rest_v0.put("users/#{@user_name}", edited_user)
ui.msg("Saved #{@user_name}.")
unless result["private_key"].nil?
if config[:filename]
diff --git a/lib/chef/knife/user_list.rb b/lib/chef/knife/user_list.rb
index 2a7e6a0e79..b0b709b642 100644
--- a/lib/chef/knife/user_list.rb
+++ b/lib/chef/knife/user_list.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,6 @@
# limitations under the License.
#
-require_relative "../mixin/root_rest"
require_relative "../knife"
class Chef
@@ -30,10 +29,16 @@ class Chef
long: "--with-uri",
description: "Show corresponding URIs."
- include Chef::Mixin::RootRestv0
+ deps do
+ require_relative "../user_v1"
+ end
+
+ def user
+ @user_field ||= Chef::UserV1.new
+ end
def run
- results = root_rest.get("users")
+ results = user.chef_root_rest_v0.get("users")
output(format_list_for_display(results))
end
diff --git a/lib/chef/knife/user_password.rb b/lib/chef/knife/user_password.rb
index 7a237b9643..06e83e4f52 100644
--- a/lib/chef/knife/user_password.rb
+++ b/lib/chef/knife/user_password.rb
@@ -1,6 +1,6 @@
#
# Author:: Tyler Cloke (<tyler@getchef.com>)
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -27,7 +26,13 @@ class Chef
short: "-e",
description: "Enable external authentication for this user (such as LDAP)"
- include Chef::Mixin::RootRestv0
+ deps do
+ require_relative "../user_v1"
+ end
+
+ def user
+ @user_field ||= Chef::UserV1.new
+ end
def run
# check that correct number of args was passed, should be either
@@ -50,18 +55,18 @@ class Chef
# true or false, there is no way of knowing if the user is using ldap or not,
# so we will update the user every time, instead of checking if we are actually
# changing anything before we PUT.
- user = root_rest.get("users/#{user_name}")
+ result = user.chef_root_rest_v0.get("users/#{user_name}")
- user["password"] = password unless password.nil?
+ result["password"] = password unless password.nil?
# if --enable-external-auth was passed, enable it, else disable it.
# there is never a situation where we would want to enable ldap
# AND change the password. changing the password means that the user
# wants to disable ldap and put user in recover (if they are using ldap).
- user["recovery_authentication_enabled"] = !config[:enable_external_auth]
+ result["recovery_authentication_enabled"] = !config[:enable_external_auth]
begin
- root_rest.put("users/#{user_name}", user)
+ user.chef_root_rest_v0.put("users/#{user_name}", result)
rescue => e
raise e
end
diff --git a/lib/chef/knife/user_show.rb b/lib/chef/knife/user_show.rb
index 4383070e98..f3caf1bec7 100644
--- a/lib/chef/knife/user_show.rb
+++ b/lib/chef/knife/user_show.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
#
require_relative "../knife"
-require_relative "../mixin/root_rest"
class Chef
class Knife
@@ -31,7 +30,13 @@ class Chef
long: "--with-orgs",
short: "-l"
- include Chef::Mixin::RootRestv0
+ deps do
+ require_relative "../user_v1"
+ end
+
+ def user
+ @user_field ||= Chef::UserV1.new
+ end
def run
@user_name = @name_args[0]
@@ -42,9 +47,9 @@ class Chef
exit 1
end
- results = root_rest.get("users/#{@user_name}")
+ results = user.chef_root_rest_v0.get("users/#{@user_name}")
if config[:with_orgs]
- orgs = root_rest.get("users/#{@user_name}/organizations")
+ orgs = user.chef_root_rest_v0.get("users/#{@user_name}/organizations")
results["organizations"] = orgs.map { |o| o["organization"]["name"] }
end
output(format_for_display(results))
diff --git a/lib/chef/mixin/root_rest.rb b/lib/chef/mixin/root_rest.rb
deleted file mode 100644
index 02462fb3cb..0000000000
--- a/lib/chef/mixin/root_rest.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 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 "chef/server_api"
-class Chef
- module Mixin
- module RootRestv0
- def root_rest
- # Use v0 API for now
- # Rather than upgrade all of this code to move to v1, the goal is to remove the
- # need for this plugin. See
- # https://github.com/chef/chef/issues/3517
- @root_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root])
- end
- end
- end
-end
diff --git a/lib/chef/org/group_operations.rb.old b/lib/chef/org/group_operations.rb.old
deleted file mode 100644
index fd75e50f41..0000000000
--- a/lib/chef/org/group_operations.rb.old
+++ /dev/null
@@ -1,60 +0,0 @@
-require_relative "../org"
-
-class Chef
- class Org
- module GroupOperations
- def group(groupname)
- @group ||= {}
- @group[groupname] ||= chef_rest.get_rest "organizations/#{name}/groups/#{groupname}"
- end
-
- def user_member_of_group?(username, groupname)
- group = group(groupname)
- group["actors"].include? username
- end
-
- def add_user_to_group(groupname, username)
- group = group(groupname)
- body_hash = {
- groupname: "#{groupname}",
- actors: {
- "users" => group["actors"].concat([username]),
- "groups" => group["groups"],
- },
- }
- chef_rest.put_rest "organizations/#{name}/groups/#{groupname}", body_hash
- end
-
- def remove_user_from_group(groupname, username)
- group = group(groupname)
- group["actors"].delete(username)
- body_hash = {
- groupname: "#{groupname}",
- actors: {
- "users" => group["actors"],
- "groups" => group["groups"],
- },
- }
- chef_rest.put_rest "organizations/#{name}/groups/#{groupname}", body_hash
- end
-
- def actor_delete_would_leave_admins_empty?
- admins = group("admins")
- if admins["groups"].empty?
- # exclude 'pivotal' but don't mutate the group since we're caching it
- if admins["actors"].include? "pivotal"
- admins["actors"].length <= 2
- else
- admins["actors"].length <= 1
- end
- else
- # We don't check recursively. If the admins group contains a group,
- # and the user is the only member of that group,
- # we'll still turn up a 'safe to delete'.
- false
- end
- end
- end
- include Chef::Org::GroupOperations
- end
-end
diff --git a/spec/unit/knife/org_delete_spec.rb b/spec/unit/knife/org_delete_spec.rb
index a39965c761..aa457cd414 100644
--- a/spec/unit/knife/org_delete_spec.rb
+++ b/spec/unit/knife/org_delete_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Snehal Dwivedi (<sdwivedi@msystechnologies.com>)
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,25 +17,25 @@
#
require "spec_helper"
+require "chef/org"
describe Chef::Knife::OrgDelete do
+ let(:chef_rest) { double("Chef::ServerAPI") }
+
before :each do
@knife = Chef::Knife::OrgDelete.new
@org_name = "foobar"
+ @org_full_name = "secretsauce"
@knife.name_args << @org_name
- end
-
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
+ @org = double("Chef::Org")
end
it "should confirm that you want to delete and then delete organizations" do
- allow(@knife).to receive(:root_rest).and_return(rest)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
+ allow(@org).to receive(:chef_rest).and_return(chef_rest)
expect(@knife.ui).to receive(:confirm).with("Do you want to delete the organization #{@org_name}")
- expect(rest).to receive(:delete).with("organizations/#{@org_name}")
+ expect(@org.chef_rest).to receive(:delete).with("organizations/#{@org_name}")
expect(@knife.ui).to receive(:output)
@knife.run
end
diff --git a/spec/unit/knife/org_list_spec.rb b/spec/unit/knife/org_list_spec.rb
index de4affe83c..d4152b66e3 100644
--- a/spec/unit/knife/org_list_spec.rb
+++ b/spec/unit/knife/org_list_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,9 +16,12 @@
#
require "spec_helper"
+require "chef/org"
describe Chef::Knife::OrgList do
+ let(:chef_rest) { double("Chef::ServerAPI") }
+
let(:orgs) do
{
"org1" => "first",
@@ -28,10 +31,11 @@ describe Chef::Knife::OrgList do
end
before :each do
- @rest = double("Chef::ServerAPI")
- allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
- allow(@rest).to receive(:get).with("organizations").and_return(orgs)
+ @org = double("Chef::Org")
@knife = Chef::Knife::OrgList.new
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
+ allow(@org).to receive(:chef_rest).and_return(chef_rest)
+ allow(@org.chef_rest).to receive(:get).with("organizations").and_return(orgs)
end
describe "with no arguments" do
diff --git a/spec/unit/knife/org_show_spec.rb b/spec/unit/knife/org_show_spec.rb
index 7c7e044b64..90765f4273 100644
--- a/spec/unit/knife/org_show_spec.rb
+++ b/spec/unit/knife/org_show_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Snehal Dwivedi (<sdwivedi@msystechnologies.com>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,27 +21,24 @@ require "chef/org"
describe Chef::Knife::OrgShow do
+ let(:chef_rest) { double("Chef::ServerAPI") }
+
before :each do
@knife = Chef::Knife::OrgShow.new
@org_name = "foobar"
@knife.name_args << @org_name
- end
-
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
+ @org = double("Chef::Org")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
+ allow(@org).to receive(:chef_rest).and_return(chef_rest)
end
it "should load the organisation" do
- allow(@knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("organizations/#{@org_name}")
+ expect(@org.chef_rest).to receive(:get).with("organizations/#{@org_name}")
@knife.run
end
it "should pretty print the output organisation" do
- allow(@knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("organizations/#{@org_name}")
+ expect(@org.chef_rest).to receive(:get).with("organizations/#{@org_name}")
expect(@knife.ui).to receive(:output)
@knife.run
end
diff --git a/spec/unit/knife/org_user_add_spec.rb b/spec/unit/knife/org_user_add_spec.rb
index b92ceaed21..20e28d6919 100644
--- a/spec/unit/knife/org_user_add_spec.rb
+++ b/spec/unit/knife/org_user_add_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb
index 16479402a1..3a97d12817 100644
--- a/spec/unit/knife/user_create_spec.rb
+++ b/spec/unit/knife/user_create_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Steven Danna (<steve@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,11 +38,7 @@ describe Chef::Knife::UserCreate do
allow(knife.ui).to receive(:warn)
end
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(root_rest)
- end
+ let(:chef_root_rest_v0) { double("Chef::ServerAPI") }
context "when USERNAME isn't specified" do
# from spec/support/shared/unit/knife_shared.rb
@@ -81,6 +77,8 @@ describe Chef::Knife::UserCreate do
before :each do
@user = double("Chef::User")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
allow(Chef::User).to receive(:new).and_return(@user)
@key = "You don't come into cooking to get rich - Ramsay"
allow(@user).to receive(:[]).with("private_key").and_return(@key)
@@ -89,8 +87,7 @@ describe Chef::Knife::UserCreate do
end
it "creates an user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
end
end
@@ -99,6 +96,7 @@ describe Chef::Knife::UserCreate do
before do
@user = double("Chef::User")
allow(Chef::User).to receive(:new).and_return(@user)
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
@key = "You don't come into cooking to get rich - Ramsay"
allow(@user).to receive(:[]).with("private_key").and_return(@key)
knife.name_args = %w{some_user some_display_name some_first_name some_last_name some_email some_password}
@@ -110,8 +108,8 @@ describe Chef::Knife::UserCreate do
end
it "sets all the mandatory fields" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.username).to eq("some_user")
expect(knife.user.display_name).to eq("some_display_name")
@@ -125,6 +123,7 @@ describe Chef::Knife::UserCreate do
knife.config[:user_key] = "some_key"
knife.config[:prevent_keygen] = true
end
+
it "prints the usage" do
expect(knife).to receive(:show_usage)
expect { knife.run }.to raise_error(SystemExit)
@@ -142,8 +141,8 @@ describe Chef::Knife::UserCreate do
end
it "does not set user.create_key" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.create_key).to be_falsey
end
@@ -151,8 +150,8 @@ describe Chef::Knife::UserCreate do
context "when --prevent-keygen is not passed" do
it "sets user.create_key to true" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.create_key).to be_truthy
end
@@ -166,8 +165,8 @@ describe Chef::Knife::UserCreate do
end
it "sets user.public_key" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.public_key).to eq("some_key")
end
@@ -175,8 +174,8 @@ describe Chef::Knife::UserCreate do
context "when --user-key is not passed" do
it "does not set user.public_key" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.public_key).to be_nil
end
@@ -188,14 +187,15 @@ describe Chef::Knife::UserCreate do
before :each do
@user = double("Chef::User")
allow(Chef::User).to receive(:new).and_return(@user)
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
@key = "You don't come into cooking to get rich - Ramsay"
allow(@user).to receive(:[]).with("private_key").and_return(@key)
knife.name_args = name_args
end
it "creates an user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
expect(knife.ui).to receive(:msg).with(@key)
knife.run
end
@@ -212,10 +212,8 @@ describe Chef::Knife::UserCreate do
}
it "creates an user, associates a user, and adds it to the admins group" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
- expect(rest).to receive(:post).with("organizations/ramsay/association_requests", request_body).and_return(@user)
- expect(rest).to receive(:put).with("users/some_user/association_requests/1", { response: "accept" })
+ expect(@user.chef_root_rest_v0).to receive(:post).with("organizations/ramsay/association_requests", request_body).and_return(@user)
+ expect(@user.chef_root_rest_v0).to receive(:put).with("users/some_user/association_requests/1", { response: "accept" })
knife.run
end
end
diff --git a/spec/unit/knife/user_delete_spec.rb b/spec/unit/knife/user_delete_spec.rb
index 924cc44b8d..64d9679895 100644
--- a/spec/unit/knife/user_delete_spec.rb
+++ b/spec/unit/knife/user_delete_spec.rb
@@ -1,5 +1,5 @@
#
-# # Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,8 @@
require "spec_helper"
require "chef/org"
+Chef::Knife::UserDelete.load_deps
+
describe Chef::Knife::UserDelete do
subject(:knife) { Chef::Knife::UserDelete.new }
diff --git a/spec/unit/knife/user_edit_spec.rb b/spec/unit/knife/user_edit_spec.rb
index c160f8c402..54a44890e0 100644
--- a/spec/unit/knife/user_edit_spec.rb
+++ b/spec/unit/knife/user_edit_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/knife/user_list_spec.rb b/spec/unit/knife/user_list_spec.rb
index a5895cf82d..d91ec09434 100644
--- a/spec/unit/knife/user_list_spec.rb
+++ b/spec/unit/knife/user_list_spec.rb
@@ -18,6 +18,8 @@
require "spec_helper"
+Chef::Knife::UserList.load_deps
+
describe Chef::Knife::UserList do
let(:knife) { Chef::Knife::UserList.new }
diff --git a/spec/unit/knife/user_password_spec.rb b/spec/unit/knife/user_password_spec.rb
index c34f2074a5..d53abfb34d 100644
--- a/spec/unit/knife/user_password_spec.rb
+++ b/spec/unit/knife/user_password_spec.rb
@@ -19,23 +19,22 @@
require "spec_helper"
require "chef/org"
+Chef::Knife::UserDelete.load_deps
+
describe Chef::Knife::UserPassword do
+ let(:chef_root_rest_v0) { double("Chef::ServerAPI") }
+
before :each do
@knife = Chef::Knife::UserPassword.new
@user_name = "foobar"
@password = "abc123"
@user = double("Chef::User")
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
allow(Chef::User).to receive(:new).and_return(@user)
@key = "You don't come into cooking to get rich - Ramsay"
end
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
- end
-
describe "should change user's password" do
before :each do
@knife.name_args << @user_name << @password
@@ -43,12 +42,11 @@ describe Chef::Knife::UserPassword do
it "with username and password" do
result = { "password" => [], "recovery_authentication_enabled" => true }
-
- allow(@knife).to receive(:root_rest).and_return(rest)
allow(@user).to receive(:[]).with("organization")
- expect(rest).to receive(:get).with("users/#{@user_name}").and_return(result)
- expect(rest).to receive(:put).with("users/#{@user_name}", result)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/#{@user_name}").and_return(result)
+ expect(@user.chef_root_rest_v0).to receive(:put).with("users/#{@user_name}", result)
expect(@knife.ui).to receive(:msg).with("Authentication info updated for #{@user_name}.")
@knife.run
diff --git a/spec/unit/knife/user_show_spec.rb b/spec/unit/knife/user_show_spec.rb
index ec473f5e7c..273cf638ee 100644
--- a/spec/unit/knife/user_show_spec.rb
+++ b/spec/unit/knife/user_show_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,14 +19,20 @@
require "spec_helper"
require "chef/org"
+Chef::Knife::UserShow.load_deps
+
describe Chef::Knife::UserShow do
let(:knife) { Chef::Knife::UserShow.new }
let(:user_mock) { double("user_mock") }
+ let(:chef_root_rest_v0) { double("Chef::ServerAPI") }
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
+ before :each do
+ @user_name = "foobar"
+ @password = "abc123"
+ @user = double("Chef::User")
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
+ allow(Chef::User).to receive(:new).and_return(@user)
+ @key = "You don't come into cooking to get rich - Ramsay"
end
describe "withot organisation argument" do
@@ -36,14 +42,14 @@ describe Chef::Knife::UserShow do
end
it "should load the user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("users/my_user")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/my_user")
knife.run
end
it "loads and displays the user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("users/my_user")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/my_user")
expect(knife).to receive(:format_for_display)
knife.run
end
@@ -75,10 +81,10 @@ describe Chef::Knife::UserShow do
result = { "organizations" => [] }
knife.config[:with_orgs] = true
- allow(knife).to receive(:root_rest).and_return(rest)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
allow(@org).to receive(:[]).with("organization").and_return({ "name" => "test" })
- expect(rest).to receive(:get).with("users/#{@user_name}").and_return(result)
- expect(rest).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/#{@user_name}").and_return(result)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs)
knife.run
end
end