diff options
-rw-r--r-- | Gemfile | 10 | ||||
-rw-r--r-- | Rakefile | 12 | ||||
-rw-r--r-- | lib/chef_zero/chef_data/default_creator.rb | 5 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/principal_endpoint.rb | 4 | ||||
-rw-r--r-- | lib/chef_zero/server.rb | 4 | ||||
-rw-r--r-- | spec/run_oc_pedant.rb | 49 | ||||
-rw-r--r-- | spec/support/oc_pedant.rb | 45 |
7 files changed, 97 insertions, 32 deletions
@@ -4,6 +4,12 @@ gemspec gem 'rest-client', :github => 'chef/rest-client' # we were using e9bf7fe4440afd34856401831b30636100be958b, but now float on latest release. -gem 'oc-chef-pedant', :github => 'chef/chef-server' +gem 'oc-chef-pedant', :github => 'chef/chef-server', :branch => 'jk/multiuser_tag' -gem 'chef', :github => 'chef/chef' +# gem 'oc-chef-pedant', :path => "../chef-server" + +# bundler resolve failure on "rspec_junit_formatter" +# gem 'chef-pedant', :github => 'opscode/chef-pedant', :ref => "server-cli-option" + +gem 'chef', :github => 'chef/chef', :branch => 'invitations-and-members' +# gem 'chef', :path => "../chef" @@ -15,6 +15,18 @@ task :pedant do require File.expand_path('spec/run_oc_pedant') end +desc "run pedant with CHEF_FS set" +task :cheffs do + ENV['CHEF_FS'] = "yes" + require File.expand_path('spec/run_oc_pedant') +end + +desc "run pedant with FILE_STORE set" +task :filestore do + ENV['FILE_STORE'] = "yes" + require File.expand_path('spec/run_oc_pedant') +end + desc "run oc pedant" task :oc_pedant do require File.expand_path('spec/run_oc_pedant') diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb index d1a0118..8a5b7fb 100644 --- a/lib/chef_zero/chef_data/default_creator.rb +++ b/lib/chef_zero/chef_data/default_creator.rb @@ -378,11 +378,12 @@ module ChefZero # Non-default containers do not get superusers added to them, # because reasons. unless path.size == 4 && path[0] == 'organizations' && path[2] == 'containers' && !exists?(path) - owners |= superusers + owners += superusers end end - owners.uniq + # we don't de-dup this list, because pedant expects to see ["pivotal", "pivotal"] in some cases. + owners end def default_acl(acl_path, acl={}) diff --git a/lib/chef_zero/endpoints/principal_endpoint.rb b/lib/chef_zero/endpoints/principal_endpoint.rb index 8cad07c..b1f4efb 100644 --- a/lib/chef_zero/endpoints/principal_endpoint.rb +++ b/lib/chef_zero/endpoints/principal_endpoint.rb @@ -8,16 +8,20 @@ module ChefZero class PrincipalEndpoint < RestBase def get(request) name = request.rest_path[-1] + # If /organizations/ORG/users/NAME exists, use this user (only org members have precedence over clients). hey are an org member. json = get_data(request, request.rest_path[0..1] + [ 'users', name ], :nil) if json type = 'user' org_member = true else + # If /organizations/ORG/clients/NAME exists, use the client. json = get_data(request, request.rest_path[0..1] + [ 'clients', name ], :nil) if json type = 'client' org_member = true else + # If there is no client with that name, check for a user (/users/NAME) and return that with + # org_member = false. json = get_data(request, [ 'users', name ], :nil) if json type = 'user' diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index d9e3931..1686301 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -485,7 +485,7 @@ module ChefZero private - def open_source_endpoints + def endpoints result = if options[:osc_compat] # OSC-only [ @@ -581,7 +581,7 @@ module ChefZero def app return @app if @app - router = RestRouter.new(open_source_endpoints) + router = RestRouter.new(endpoints) router.not_found = NotFoundEndpoint.new if options[:single_org] diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index b5cecec..726279f 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -5,7 +5,7 @@ require 'bundler/setup' require 'chef_zero/server' require 'rspec/core' -def start_server(chef_repo_path) +def start_cheffs_server(chef_repo_path) require 'chef/version' require 'chef/config' require 'chef/chef_fs/config' @@ -22,12 +22,24 @@ def start_server(chef_repo_path) end # Start the new server - Chef::Config.repo_mode = 'everything' + Chef::Config.repo_mode = 'hosted_everything' Chef::Config.chef_repo_path = chef_repo_path Chef::Config.versioned_cookbooks = true - chef_fs = Chef::ChefFS::Config.new.local_fs - data_store = Chef::ChefFS::ChefFSDataStore.new(chef_fs) - server = ChefZero::Server.new(:port => 8889, :single_org => false, :data_store => data_store)#, :log_level => :debug) + chef_fs_config = Chef::ChefFS::Config.new + + data_store = Chef::ChefFS::ChefFSDataStore.new(chef_fs_config.local_fs, chef_fs_config.chef_config) + data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, 'pedant-testorg') + data_store = ChefZero::DataStore::DefaultFacade.new(data_store, 'pedant-testorg', false) + data_store.create(%w(organizations pedant-testorg users), 'pivotal', '{}') + data_store.set(%w(organizations pedant-testorg groups admins), '{ "users": [ "pivotal" ] }') + data_store.set(%w(organizations pedant-testorg groups users), '{ "users": [ "pivotal" ] }') + + server = ChefZero::Server.new( + port: 8889, + data_store: data_store, + single_org: false, + #log_level: :debug + ) server.start_background server end @@ -47,7 +59,7 @@ begin elsif ENV['CHEF_FS'] require 'tmpdir' tmpdir = Dir.mktmpdir - start_server(tmpdir) + server = start_cheffs_server(tmpdir) else server = ChefZero::Server.new(:port => 8889, :single_org => false)#, :log_level => :debug) @@ -61,14 +73,21 @@ begin # Pedant::Config.rerun = true Pedant.config.suite = 'api' - Pedant.config.internal_server = Pedant::Config.search_server = 'http://localhost:8889' - - # see dummy_endpoint.rb. - Pedant.config.search_commit_url = "/dummy" - Pedant::Config.search_url_fmt = "/dummy?fq=+X_CHEF_type_CHEF_X:%{type}&q=%{query}&wt=json" Pedant.config[:config_file] = 'spec/support/oc_pedant.rb' - Pedant.config[:server_api_version] = 0 + + # Because ChefFS can only ever have one user (pivotal), we can't do most of the + # tests that involve multiple + chef_fs_skips = if ENV['CHEF_FS'] + [ '--skip-association', + '--skip-users', + '--skip-organizations', + '--skip-multiuser', + '--skip-policies' # these are expected to be broken, they're what we're trying to fix. + ] + else + [] + end # "the goal is that only authorization, authentication and validation tests are turned off" - @jkeiser Pedant.setup([ @@ -88,10 +107,12 @@ begin '--skip-cookbook-artifacts', '--skip-containers', '--skip-api-v1' + ] + chef_fs_skips) - ]) + fail_fast = [] + # fail_fast = ["--fail-fast"] - result = RSpec::Core::Runner.run(Pedant.config.rspec_args) + result = RSpec::Core::Runner.run(Pedant.config.rspec_args + fail_fast) server.stop if server.running? ensure diff --git a/spec/support/oc_pedant.rb b/spec/support/oc_pedant.rb index e3bcf27..cc62dd4 100644 --- a/spec/support/oc_pedant.rb +++ b/spec/support/oc_pedant.rb @@ -45,6 +45,16 @@ maximum_search_time 0 # # to be enabled for Pedant tests to work correctly explicit_port_url true +server_api_version 0 + +internal_server chef_server + +# see dummy_endpoint.rb for details. +search_server chef_server +search_commit_url "/dummy" +search_url_fmt "/dummy?fq=+X_CHEF_type_CHEF_X:%{type}&q=%{query}&wt=json" + + # We're starting to break tests up into groups based on different # criteria. The proper API tests (the results of which are viewable # to OPC customers) should be the only ones run by Pedant embedded in @@ -59,9 +69,12 @@ explicit_port_url true # value. include_internal false -# This is the bit that is different from pedant.rb -org({:name => "pedant-testorg", - :create_me => true}) +key = 'spec/support/stickywicket.pem' + +org(name: "pedant-testorg", + create_me: !ENV['CHEF_FS'], + validator_key: key) + internal_account_url chef_server delete_org true @@ -77,6 +90,12 @@ superuser_name 'pivotal' superuser_key key webui_key key +def cheffs_or_else_user(value) + ENV['CHEF_FS'] ? "pivotal" : value +end + +keyfile_maybe = ENV['CHEF_FS'] ? { key_file: key } : { key_file: nil } + requestors({ :clients => { # The the admin user, for the purposes of getting things rolling @@ -102,24 +121,26 @@ requestors({ :users => { # An administrator in the testing organization :admin => { - :name => "pedant_admin_user", - :create_me => true, + :name => cheffs_or_else_user("pedant_admin_user"), + :create_me => !ENV['CHEF_FS'], + :associate => !ENV['CHEF_FS'], :create_knife => true - }, + }.merge(keyfile_maybe), :non_admin => { - :name => "pedant_user", - :create_me => true, + :name => cheffs_or_else_user("pedant_user"), + :create_me => !ENV['CHEF_FS'], + :associate => !ENV['CHEF_FS'], :create_knife => true - }, + }.merge(keyfile_maybe), # A user that is not a member of the testing organization :bad => { - :name => "pedant-nobody", - :create_me => true, + :name => cheffs_or_else_user("pedant-nobody"), + :create_me => !ENV['CHEF_FS'], :create_knife => true, :associate => false - }, + }.merge(keyfile_maybe), } }) |