summaryrefslogtreecommitdiff
path: root/spec/integration/knife
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-08-31 10:07:21 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-09-05 12:09:08 -0700
commit865ae8a61ccb3395c7f738871be0bf7a2d1b02ce (patch)
tree2e60dd013042dd4091a30206e33d5b7becce5b8e /spec/integration/knife
parent27b05b2396459f3d84f0ebd924f8adc44a906cd1 (diff)
downloadchef-865ae8a61ccb3395c7f738871be0bf7a2d1b02ce.tar.gz
Add org.json, members.json, invitations.json for full org download
and upload support
Diffstat (limited to 'spec/integration/knife')
-rw-r--r--spec/integration/knife/delete_spec.rb29
-rw-r--r--spec/integration/knife/download_spec.rb76
-rw-r--r--spec/integration/knife/list_spec.rb103
-rw-r--r--spec/integration/knife/upload_spec.rb153
4 files changed, 358 insertions, 3 deletions
diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb
index dc52cc71a4..a9ba9dc3e1 100644
--- a/spec/integration/knife/delete_spec.rb
+++ b/spec/integration/knife/delete_spec.rb
@@ -962,9 +962,12 @@ EOM
end
end
- when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do
+ when_the_chef_server "is in Enterprise mode", :focus, :osc_compat => false, :single_org => false do
before do
- organization 'foo'
+ organization 'foo' do
+ container 'x', {}
+ group 'x', {}
+ end
end
before :each do
@@ -974,5 +977,27 @@ EOM
it 'knife delete /acls/containers/environments.json fails with a reasonable error' do
knife('delete /acls/containers/environments.json').should_fail "ERROR: /acls/containers/environments.json (remote) cannot be deleted.\n"
end
+
+ it 'knife delete /containers/x.json succeeds' do
+ knife('delete /containers/x.json').should_succeed "Deleted /containers/x.json\n"
+ knife('raw /containers/x.json').should_fail(/404/)
+ end
+
+ it 'knife delete /groups/x.json succeeds' do
+ knife('delete /groups/x.json').should_succeed "Deleted /groups/x.json\n"
+ knife('raw /groups/x.json').should_fail(/404/)
+ end
+
+ it 'knife delete /org.json fails with a reasonable error' do
+ knife('delete /org.json').should_fail "ERROR: /org.json (remote) cannot be deleted.\n"
+ end
+
+ it 'knife delete /invitations.json fails with a reasonable error' do
+ knife('delete /invitations.json').should_fail "ERROR: /invitations.json (remote) cannot be deleted.\n"
+ end
+
+ it 'knife delete /members.json fails with a reasonable error' do
+ knife('delete /members.json').should_fail "ERROR: /members.json (remote) cannot be deleted.\n"
+ end
end
end
diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb
index 4126acc9fc..17779d1f47 100644
--- a/spec/integration/knife/download_spec.rb
+++ b/spec/integration/knife/download_spec.rb
@@ -1091,4 +1091,80 @@ EOM
end
end
end
+
+ when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do
+ before do
+ organization 'foo' do
+ container 'x', {}
+ group 'x', {}
+ end
+ end
+
+ before :each do
+ Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo')
+ end
+
+ when_the_repository 'is empty' do
+ it 'knife download / downloads everything' do
+ knife('download /').should_succeed <<EOM
+Created /acls
+Created /acls/clients
+Created /acls/clients/foo-validator.json
+Created /acls/containers
+Created /acls/containers/clients.json
+Created /acls/containers/containers.json
+Created /acls/containers/cookbooks.json
+Created /acls/containers/data.json
+Created /acls/containers/environments.json
+Created /acls/containers/groups.json
+Created /acls/containers/nodes.json
+Created /acls/containers/roles.json
+Created /acls/containers/sandboxes.json
+Created /acls/containers/x.json
+Created /acls/cookbooks
+Created /acls/data_bags
+Created /acls/environments
+Created /acls/environments/_default.json
+Created /acls/groups
+Created /acls/groups/admins.json
+Created /acls/groups/billing-admins.json
+Created /acls/groups/clients.json
+Created /acls/groups/users.json
+Created /acls/groups/x.json
+Created /acls/nodes
+Created /acls/roles
+Created /acls/organization.json
+Created /clients
+Created /clients/foo-validator.json
+Created /containers
+Created /containers/clients.json
+Created /containers/containers.json
+Created /containers/cookbooks.json
+Created /containers/data.json
+Created /containers/environments.json
+Created /containers/groups.json
+Created /containers/nodes.json
+Created /containers/roles.json
+Created /containers/sandboxes.json
+Created /containers/x.json
+Created /cookbooks
+Created /data_bags
+Created /environments
+Created /environments/_default.json
+Created /groups
+Created /groups/admins.json
+Created /groups/billing-admins.json
+Created /groups/clients.json
+Created /groups/users.json
+Created /groups/x.json
+Created /invitations.json
+Created /members.json
+Created /nodes
+Created /org.json
+Created /roles
+EOM
+ knife('diff --name-status /').should_succeed ''
+ end
+ end
+ end
end
diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb
index 1f70d3bc3d..48e85f43bb 100644
--- a/spec/integration/knife/list_spec.rb
+++ b/spec/integration/knife/list_spec.rb
@@ -651,7 +651,7 @@ EOM
Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo')
end
- context 'and has plenty of stuff in it' do
+ context 'and is empty' do
it "knife list / returns all top level directories" do
knife('list /').should_succeed <<EOM
/acls
@@ -755,4 +755,105 @@ EOM
end
end
end
+
+ when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do
+ before do
+ organization 'foo'
+ end
+
+ before :each do
+ Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo')
+ end
+
+ it 'knife list -R / returns everything' do
+ knife('list -R /').should_succeed <<EOM
+/:
+acls
+clients
+containers
+cookbooks
+data_bags
+environments
+groups
+invitations.json
+members.json
+nodes
+org.json
+roles
+
+/acls:
+clients
+containers
+cookbooks
+data_bags
+environments
+groups
+nodes
+organization.json
+roles
+
+/acls/clients:
+foo-validator.json
+
+/acls/containers:
+clients.json
+containers.json
+cookbooks.json
+data.json
+environments.json
+groups.json
+nodes.json
+roles.json
+sandboxes.json
+
+/acls/cookbooks:
+
+/acls/data_bags:
+
+/acls/environments:
+_default.json
+
+/acls/groups:
+admins.json
+billing-admins.json
+clients.json
+users.json
+
+/acls/nodes:
+
+/acls/roles:
+
+/clients:
+foo-validator.json
+
+/containers:
+clients.json
+containers.json
+cookbooks.json
+data.json
+environments.json
+groups.json
+nodes.json
+roles.json
+sandboxes.json
+
+/cookbooks:
+
+/data_bags:
+
+/environments:
+_default.json
+
+/groups:
+admins.json
+billing-admins.json
+clients.json
+users.json
+
+/nodes:
+
+/roles:
+EOM
+ end
+ end
end
diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb
index 4e447589f3..05d33d1a17 100644
--- a/spec/integration/knife/upload_spec.rb
+++ b/spec/integration/knife/upload_spec.rb
@@ -1216,4 +1216,157 @@ EOM
end
end
end
+
+ when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do
+ before do
+ user 'foo', {}
+ user 'bar', {}
+ user 'foobar', {}
+ organization 'foo', { 'full_name' => 'Something'}
+ end
+
+ before :each do
+ Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo')
+ end
+
+ context 'and has nothing but a single group named blah' do
+ group 'blah', {}
+
+ when_the_repository 'has one of each thing' do
+
+ before do
+ # TODO We have to upload acls for an existing group due to a lack of
+ # dependency detection during upload. Fix that!
+ file 'acls/groups/blah.json', {}
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'containers/x.json', {}
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'data_bags/x/y.json', {}
+ file 'environments/x.json', {}
+ file 'groups/x.json', {}
+ file 'invitations.json', [ 'foo' ]
+ file 'members.json', [ 'bar' ]
+ file 'nodes/x.json', {}
+ file 'org.json', { 'full_name' => 'wootles' }
+ file 'roles/x.json', {}
+ end
+
+ it 'knife upload / uploads everything' do
+ knife('upload /').should_succeed <<EOM
+Updated /acls/groups/blah.json
+Created /clients/x.json
+Created /containers/x.json
+Created /cookbooks/x
+Created /data_bags/x
+Created /data_bags/x/y.json
+Created /environments/x.json
+Created /groups/x.json
+Updated /invitations.json
+Updated /members.json
+Created /nodes/x.json
+Updated /org.json
+Created /roles/x.json
+EOM
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'foo' ]
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar' ]
+ end
+ end
+
+ when_the_repository 'has an org.json that does not change full_name' do
+ before do
+ file 'org.json', { 'full_name' => 'Something' }
+ end
+
+ it 'knife upload / emits a warning for bar and adds foo and foobar' do
+ knife('upload /').should_succeed ''
+ api.get('/')['full_name'].should == 'Something'
+ end
+ end
+
+ when_the_repository 'has an org.json that changes full_name' do
+ before do
+ file 'org.json', { 'full_name' => 'Something Else'}
+ end
+
+ it 'knife upload / emits a warning for bar and adds foo and foobar' do
+ knife('upload /').should_succeed "Updated /org.json\n"
+ api.get('/')['full_name'].should == 'Something Else'
+ end
+ end
+
+ context 'and has invited foo and bar is already a member' do
+ org_invite 'foo'
+ org_member 'bar'
+
+ when_the_repository 'wants to invite foo, bar and foobar' do
+ before do
+ file 'invitations.json', [ 'foo', 'bar', 'foobar' ]
+ end
+
+ it 'knife upload / emits a warning for bar and invites foobar' do
+ knife('upload /').should_succeed "Updated /invitations.json\n", :stderr => "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n"
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'foo', 'foobar' ]
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar' ]
+ end
+ end
+
+ when_the_repository 'wants to make foo, bar and foobar members' do
+ before do
+ file 'members.json', [ 'foo', 'bar', 'foobar' ]
+ end
+
+ it 'knife upload / emits a warning for bar and adds foo and foobar' do
+ knife('upload /').should_succeed "Updated /members.json\n"
+ api.get('association_requests').map { |a| a['username'] }.should == [ ]
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar', 'foo', 'foobar' ]
+ end
+ end
+
+ when_the_repository 'wants to invite foo and have bar as a member' do
+ before do
+ file 'invitations.json', [ 'foo' ]
+ file 'members.json', [ 'bar' ]
+ end
+
+ it 'knife upload / does nothing' do
+ knife('upload /').should_succeed ''
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'foo' ]
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar' ]
+ end
+ end
+ end
+
+ context 'and has invited bar and foo' do
+ org_invite 'bar', 'foo'
+
+ when_the_repository 'wants to invite foo and bar (different order)' do
+ before do
+ file 'invitations.json', [ 'foo', 'bar' ]
+ end
+
+ it 'knife upload / does nothing' do
+ knife('upload /').should_succeed ''
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'bar', 'foo' ]
+ api.get('users').map { |a| a['user']['username'] }.should == [ ]
+ end
+ end
+ end
+
+ context 'and has already added bar and foo as members of the org' do
+ org_member 'bar', 'foo'
+
+ when_the_repository 'wants to add foo and bar (different order)' do
+ before do
+ file 'members.json', [ 'foo', 'bar' ]
+ end
+
+ it 'knife upload / does nothing' do
+ knife('upload /').should_succeed ''
+ api.get('association_requests').map { |a| a['username'] }.should == [ ]
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar', 'foo' ]
+ end
+ end
+ end
+ end
+ end
end