Skip to content

Commit

Permalink
Merge pull request #14248 from opf/code-maintenance/51232-revise-modu…
Browse files Browse the repository at this point in the history
…lesstoragesspecfeaturesadmin_storages_specrb

[#51232] Remove skipped test cases.
  • Loading branch information
ba1ash authored Nov 27, 2023
2 parents 5541eaa + 078bf5d commit c4d5799
Showing 1 changed file with 0 additions and 249 deletions.
249 changes: 0 additions & 249 deletions modules/storages/spec/features/admin_storages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,253 +536,4 @@
end
end
end

# skipped to be revised later. broken due to removal of storage_primer_design feature flag
xit 'creates, edits and deletes storages', :webmock do
visit admin_settings_storages_path

######### Step 1: Begin Create a storage #########
# Show empty storages list
expect(page).to have_title('File storages')
expect(page.find('.title-container')).to have_text('File storages')
expect(page).to have_text(I18n.t('storages.no_results'))
page.find('.toolbar .button--icon.icon-add').click

# Create a storage - happy path
expect(page).to have_title('New storage')
expect(page.find('.title-container')).to have_text('New storage')
expect(page).to have_select('storages_storage[provider_type]', selected: 'Nextcloud')
expect(page).to have_field('storages_storage[name]', with: 'My storage')

# Test the happy path for a valid storage server (host).
# Mock a valid response (=200) for example.com, so the host validation should succeed
mock_server_capabilities_response("https://example.com")
mock_server_config_check_response("https://example.com")

# Setting to "" is needed to avoid receiving "My NextcloudNC 1"
page.find_by_id('storages_storage_name').set("")
page.find_by_id('storages_storage_name').set("NC 1")
page.find_by_id('storages_storage_host').set("https://example.com")
page.click_button('Save and continue setup')
######### Step 1: End Create a storage #########

######### Step 2: Begin Show OAuth application #########
# Show created oauth application
storage_type = I18n.t('storages.provider_types.nextcloud.name')
expect(page).to have_title("#{storage_type} #{I18n.t('storages.label_oauth_application_details')}")
oauth_app_client_id = page.find_by_id('client_id').value
expect(oauth_app_client_id.length).to eq 43
expect(page.find_by_id('secret').value.length).to eq 43
page.find('a.button', text: 'Done. Continue setup').click
######### Step 2: End Show OAuth application #########

######### Step 3: Begin Add OAuthClient #########
# Add OAuthClient - Testing a number of different invalid states
# However, more detailed checks are performed in the service spec.
expect(page).to have_title("OAuth client details")

# Set the client_id but leave client_secret empty
page.find_by_id('oauth_client_client_id').set("0123456789")
page.click_button('Save')
# Check that we're still on the same page
expect(page).to have_title("OAuth client details")

# Set client_id to be empty but set the client_secret
page.find_by_id('oauth_client_client_id').set("")
page.find_by_id('oauth_client_client_secret').set("1234567890")
page.click_button('Save')
# Check that we're still on the same page
expect(page).to have_title("OAuth client details")

# Both client_id and client_secret valid
page.find_by_id('oauth_client_client_id').set("0123456789")
page.find_by_id('oauth_client_client_secret').set("1234567890")
page.click_button('Save')
######### Step 3: End Add OAuthClient #########

######### Step 4: Begin Automatically managed project folders #########
# Nextcloud - Automatically managed project folders settings
# Switch is checked by default, expects input for password
expect(page).to have_title("Automatically managed project folders")
automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
application_password_input = page.find_by_id('storages_nextcloud_storage_password')
expect(automatically_managed_switch).to be_checked
expect(application_password_input.value).to be_empty

# Clicking submit with application password empty should show an error
page.click_button('Done, complete setup')
# Check that we're still on the same page
expect(page).to have_title("Automatically managed project folders")
expect(page).to have_content("Password can't be blank.")

# Test the error path for an invalid storage password.
# Mock a valid response (=401) for example.com, so the password validation should fail
mock_nextcloud_application_credentials_validation("https://example.com", password: "1234567890", response_code: 401)
automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
expect(automatically_managed_switch).to be_checked
page.fill_in 'storages_nextcloud_storage_password', with: "1234567890"
# Clicking submit with application password empty should show an error
page.click_button('Save')
# Check that we're still on the same page
expect(page).to have_title("Automatically managed project folders")
expect(page).to have_content("Password is not valid.")

# Test the happy path for a valid storage password.
# Mock a valid response (=200) for example.com, so the password validation should succeed
# Fill in application password and submit
mock_nextcloud_application_credentials_validation("https://example.com", password: "1234567890")
automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
expect(automatically_managed_switch).to be_checked
page.fill_in 'storages_nextcloud_storage_password', with: "1234567890"
page.click_button('Save')
expect(page).to have_text("Active")
expect(page).to have_text("●●●●●●●●●●●●●●●●")
######### Step 4: End Automatically managed project folders #########

# Edit storage again
expect(page).to have_title("Edit: NC 1")
expect(page).not_to have_select("storages_storage[provider_type]")
expect(page).to have_text("NC 1")
expect(page.find('.title-container')).to have_text('Edit: NC 1')

# Edit page - With option to replace the OAuth2 client
# Check presence of a "Replace" link and follow it
page.find('a', text: 'Replace Nextcloud').click

alert_text = page.driver.browser.switch_to.alert.text
expect(alert_text).to have_text("Are you sure?")
page.driver.browser.switch_to.alert.accept

# The form the new OAuth client shall be empty as we are creating a new one.
expect(page).not_to have_text("234567")

page.find_by_id('oauth_client_client_id').set("2345678901")
page.find_by_id('oauth_client_client_secret').set("3456789012")
page.click_button('Replace')

# Check for client_id
expect(page).to have_text("2345678901")

# Test the behavior of a failed host validation with code 400 (Bad Request)
# simulating server not running Nextcloud
mock_server_capabilities_response("https://other.example.com", response_code: '400')
page.find_by_id('storages_storage_name').set("Other NC")
page.find_by_id('storages_storage_host').set("https://other.example.com")
page.click_button('Save')

expect(page).to have_title("Edit: Other NC")
expect(page.find('.title-container')).to have_text('Edit: Other NC')
expect(page).to have_css('.op-toast--content')
expect(page).to have_text("error prohibited this Storage from being saved")

# Edit page - Check for failed Nextcloud Version
# Test the behavior of a Nextcloud server with major version too low
mock_server_capabilities_response("https://old.example.com", response_nextcloud_major_version: 18)
page.find_by_id('storages_storage_name').set("Old NC")
page.find_by_id('storages_storage_host').set("https://old.example.com")
page.click_button('Save')

expect(page).to have_title("Edit: Old NC")
expect(page).to have_css('.op-toast')
version_err = I18n.t('activerecord.errors.models.storages/storage.attributes.host.minimal_nextcloud_version_unmet')
expect(page).to have_text(version_err)

# Edit page - save working storage
# Restore the mocked working server example.com
page.find_by_id('storages_storage_host').set("https://example.com")
page.find_by_id('storages_storage_name').set("Other NC")
page.click_button('Save')

######### Begin Edit Automatically managed project folders #########
#
# Confirm update of host URL with subpath renders correctly Nextcloud/Administration link
mock_server_capabilities_response("https://example.com/with/subpath")
mock_server_config_check_response("https://example.com/with/subpath")
page.find_by_id('storages_storage_host').set("https://example.com/with/subpath")
page.click_button('Save')

# Check for updated host URL
expect(page.find_by_id('storages_storage_host').value).to eq("https://example.com/with/subpath")

page.find('a', text: 'Edit automatically managed project folders').click

expect(page).to have_title("Automatically managed project folders")
automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
application_password_input = page.find_by_id('storages_nextcloud_storage_password')
expect(automatically_managed_switch).to be_checked
expect(application_password_input.value).to be_empty
expect(application_password_input['placeholder']).to eq("●●●●●●●●●●●●●●●●")
expect(page).to have_link(
text: 'Nextcloud Administration / OpenProject',
href: 'https://example.com/with/subpath/settings/admin/openproject'
)

# Clicking submit without inputting new application password should show an error
page.click_button('Save')
# Check that we're still on the same page
expect(page).to have_title("Automatically managed project folders")
expect(page).to have_content("Password can't be blank.")

# Switch off automatically managed project folders
page.find_test_selector('spot-switch-handle').click
page.click_button('Save')
expect(page).to have_text("Inactive")
######### End Edit Automatically managed project folders #########

# List of storages
page.find("#{test_selector('op-breadcrumb')} ol li", text: "File storages").click

# Delete on List page
page.find('td.buttons .icon-delete').click

alert_text = page.driver.browser.switch_to.alert.text
expect(alert_text).to eq(I18n.t('storages.delete_warning.storage'))
page.driver.browser.switch_to.alert.accept

expect(page).to have_current_path(admin_settings_storages_path)
expect(page).not_to have_text("Other NC")
# Also check that there are no more OAuthClient instances anymore
expect(OAuthClient.count).to eq(0)
end

describe 'configuration checks' do
let!(:configured_storage) do
storage = create(:nextcloud_storage)
create(:oauth_application, integration: storage)
create(:oauth_client, integration: storage)
storage
end
let!(:unconfigured_storage) { create(:nextcloud_storage) }

# skipped to be revised later. broken due to removal of storage_primer_design feature flag
xit 'reports storages that are not configured correctly' do
visit admin_settings_storages_path

aggregate_failures 'storages view with configuration checks' do
configured_storage_table_row = page.find_by_id("storages_nextcloud_storage_#{configured_storage.id}")
unconfigured_storage_table_row = page.find_by_id("storages_nextcloud_storage_#{unconfigured_storage.id}")

expect(configured_storage_table_row).not_to have_css('.octicon-alert-fill')
expect(unconfigured_storage_table_row).to have_css('.octicon-alert-fill')
end

aggregate_failures 'individual storage view' do
within "#storages_nextcloud_storage_#{configured_storage.id}" do
page.find('td.buttons .icon-edit').click
end

expect(page).not_to have_css('.flash.flash-error')

within(test_selector('op-breadcrumb')) do
click_link 'File storages'
end

within "#storages_nextcloud_storage_#{unconfigured_storage.id}" do
page.find('td.buttons .icon-edit').click
end

expect(page).to have_css('.flash.flash-error', text: 'The setup of this storage is incomplete.')
end
end
end
end

0 comments on commit c4d5799

Please sign in to comment.