@ -38,7 +38,10 @@ shared_examples_for 'storage contract', :storage_server_helpers, webmock: true d
let ( :storage_creator ) { current_user }
before do
mock_server_capabilities_response ( storage_host ) if storage_host
if storage_host . present?
mock_server_capabilities_response ( storage_host )
mock_server_host_response ( storage_host )
end
end
it_behaves_like 'contract is valid for active admins and invalid for regular users'
@ -114,20 +117,20 @@ shared_examples_for 'storage contract', :storage_server_helpers, webmock: true d
end
context 'when provider_type is nextcloud' do
let ( :host _response_body ) { nil } # use default
let ( :host _response_code ) { nil } # use default
let ( :host _response_headers ) { nil } # use default
let ( :host _response_major_version ) { 23 }
let ( :capabilities _response_body ) { nil } # use default
let ( :capabilities _response_code ) { nil } # use default
let ( :capabilities _response_headers ) { nil } # use default
let ( :capabilities _response_major_version ) { 23 }
before do
# simulate host value changed to have GET request sent to check host URL validity
storage . host_will_change!
# simulate http response returned upon GET request
mock_server_capabilities_response ( storage_host ,
response_code : host _response_code,
response_headers : host _response_headers,
response_body : host _response_body,
response_nextcloud_major_version : host _response_major_version)
response_code : capabilities _response_code,
response_headers : capabilities _response_headers,
response_body : capabilities _response_body,
response_nextcloud_major_version : capabilities _response_major_version)
end
context 'when connection fails' do
@ -139,19 +142,19 @@ shared_examples_for 'storage contract', :storage_server_helpers, webmock: true d
end
context 'when response code is a 404 NOT FOUND' do
let ( :host _response_code ) { 404 }
let ( :capabilities _response_code ) { 404 }
include_examples 'contract is invalid' , host : :cannot_be_connected_to
end
context 'when response code is a 500 PERMISSION DENIED' do
let ( :host _response_code ) { 500 }
let ( :capabilities _response_code ) { 500 }
include_examples 'contract is invalid' , host : :cannot_be_connected_to
end
context 'when response content type is not application/json' do
let ( :host _response_headers ) do
let ( :capabilities _response_headers ) do
{
'Content-Type' = > 'text/html'
}
@ -161,22 +164,35 @@ shared_examples_for 'storage contract', :storage_server_helpers, webmock: true d
end
context 'when response is unparsable JSON' do
let ( :host _response_body ) { '{' }
let ( :capabilities _response_body ) { '{' }
include_examples 'contract is invalid' , host : :not_nextcloud_server
end
context 'when response is valid JSON but not the expected data' do
let ( :host _response_body ) { '{}' }
let ( :capabilities _response_body ) { '{}' }
include_examples 'contract is invalid' , host : :not_nextcloud_server
end
context 'when Nextcloud version is below the required minimal version which is 23' do
let ( :host _response_major_version ) { 22 }
let ( :capabilities _response_major_version ) { 22 }
include_examples 'contract is invalid' , host : :minimal_nextcloud_version_unmet
end
context 'when Nextcloud instance is not fully set up' do
let ( :host_response_code ) { 302 }
let ( :host_response_header ) { { Location : File . join ( storage_host , '/index.php/login' ) } }
before do
mock_server_host_response ( storage_host ,
response_code : host_response_code ,
response_headers : host_response_header )
end
include_examples 'contract is invalid' , host : :setup_incomplete
end
end
end
end