1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #873: Add OCCI GET /user tests

This commit is contained in:
Daniel Molina 2011-10-14 15:54:01 +02:00
parent 409b565dc8
commit 1040d34766
5 changed files with 164 additions and 0 deletions

1
src/cloud/occi/test/fixtures/user.xml vendored Normal file
View File

@ -0,0 +1 @@
<USER href="http://localhost:4567/user/0"><ID>0</ID><NAME>oneadmin</NAME><QUOTA><CPU>0</CPU><MEMORY>0</MEMORY><NUM_VMS>0</NUM_VMS><STORAGE>0</STORAGE></QUOTA><USAGE><CPU>0</CPU><MEMORY>0</MEMORY><NUM_VMS>0</NUM_VMS><STORAGE>0</STORAGE></USAGE></USER>

View File

@ -0,0 +1 @@
<USER_COLLECTION><USER href="http://localhost:4567/user/0" name="oneadmin"/><USER href="http://localhost:4567/user/1" name="my_first_occi_user"/></USER_COLLECTION>

View File

@ -0,0 +1,39 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# 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. #
#--------------------------------------------------------------------------- #
FIXTURES_PATH = File.join(File.dirname(__FILE__),'../fixtures')
$: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
# Load the testing libraries
require 'rubygems'
require 'rspec'
require 'rack/test'
# Load the Sinatra app
require 'occi-server'
# Make Rack::Test available to all spec contexts
RSpec.configure do |conf|
conf.include Rack::Test::Methods
end
# Set the Sinatra environment
set :environment, :test
# Add an app method for RSpec
def app
Sinatra::Application
end

View File

@ -0,0 +1,73 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# 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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe 'OCCI User tests' do
before(:all) do
@username_1 = "my_first_occi_user"
@userpass_1 = "my_first_occi_pass"
`oneuser create #{@username_1} #{@userpass_1}`
end
it "should list the user collection" do
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
get '/user'
last_response.status.should eql(200)
xml_body = last_response.body
user_collection = File.read(FIXTURES_PATH + '/user_collection.xml')
xml_body.strip.should eql(user_collection.strip)
end
it "should check the error if the user collection is retrieved by a non oneadmin user" do
basic_authorize('my_first_occi_user','c08c5a6c535b6060b7b2af34e0d2f0ffb7e63b28')
get '/user'
last_response.status.should eql(403)
end
it "should show the user information, no quotas and no usage" do
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
get '/user/0'
last_response.status.should eql(200)
xml_body = last_response.body
user = File.read(FIXTURES_PATH + '/user.xml')
xml_body.strip.should eql(user.strip)
end
it "should get a 404 error when trying to get a non existing user" do
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
get '/user/99'
last_response.status.should eql(404)
end
it "should get a 403 error when trying to get a different user" do
basic_authorize('my_first_occi_user','c08c5a6c535b6060b7b2af34e0d2f0ffb7e63b28')
get '/user/0'
last_response.status.should eql(403)
end
end

50
src/cloud/occi/test/test.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# 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. #
#--------------------------------------------------------------------------- #
if [ -z $ONE_LOCATION ]; then
echo "ONE_LOCATION not defined."
exit -1
fi
VAR_LOCATION="$ONE_LOCATION/var"
rm -rf $VAR_LOCATION/*
if [ "$(ls -A $VAR_LOCATION)" ]; then
echo "$VAR_LOCATION is not empty."
exit -1
fi
for j in `ls ./spec/*_spec.rb` ; do
PID=$$
oned -f &
sleep 2s;
rspec $j -f s
CODE=$?
pkill -P $PID oned
sleep 2s;
pkill -9 -P $PID oned
if [ $CODE != 0 ] ; then
exit 1
fi
find $VAR_LOCATION -mindepth 1 -delete
done