Skip to content

Commit

Permalink
nextcloud: update to 16.0.0
Browse files Browse the repository at this point in the history
Also make sure occ is always called with the non-interactive flag to
ensure it doesn't prompt (v16 started doing so when trying to enable
maintenance mode before nextcloud is installed).

The tests started failing in Trusty/Xenial against webkit, so also move
tests over to use Chrome in headless mode.

Resolve nextcloud-snap#972

Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
  • Loading branch information
kyrofa committed Apr 28, 2019
1 parent 0582854 commit 8a27bc0
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 214 deletions.
4 changes: 2 additions & 2 deletions .circleci/runtests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# Install dependencies for the gems
sudo apt install qt5-default libqt5webkit5-dev xvfb -y
# Note that the tests require chrome and chromedriver, but the CircleCI machine
# executor image already contains both.

# In order to use rvm, we need a login shell. We need to install
# Ruby v2.4.0 (the older version that is the default doesn't handle
Expand Down
4 changes: 2 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ parts:

nextcloud:
plugin: dump
source: https://download.nextcloud.com/server/releases/nextcloud-15.0.7.tar.bz2
source-checksum: sha256/3e6158951fa72010ccd50dbeac05d8df162183f7bbc62a1c6c89ed7081fa9d49
source: https://download.nextcloud.com/server/releases/nextcloud-16.0.0.tar.bz2
source-checksum: sha256/4532f7028b1d9bf060f75ac4fbbde52a59ecd9c9155f3178a038d3cf3609402e
organize:
'*': htdocs/
'.htaccess': htdocs/.htaccess
Expand Down
4 changes: 2 additions & 2 deletions src/common/utilities/common-utilities
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ wait_for_command()

enable_maintenance_mode()
{
run_command "Enabling maintenance mode" occ maintenance:mode --on
run_command "Enabling maintenance mode" occ -n maintenance:mode --on
}

disable_maintenance_mode()
{
run_command "Disabling maintenance mode" occ maintenance:mode --off
run_command "Disabling maintenance mode" occ -n maintenance:mode --off
}
10 changes: 5 additions & 5 deletions src/nextcloud/bin/nextcloud-fixer
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wait_for_apache

if nextcloud_is_installed; then
# This command can be run without putting Nextcloud into maintenance mode
occ db:add-missing-indices --no-interaction
occ -n db:add-missing-indices

# Unfortunately convert-filecache-bigint requires that Nextcloud be in maintenance
# mode, and can take some time.
Expand All @@ -23,18 +23,18 @@ if nextcloud_is_installed; then
fi
trap 'disable_maintenance_mode' EXIT

occ db:convert-filecache-bigint --no-interaction
occ -n db:convert-filecache-bigint
else
wait_for_nextcloud_to_be_installed

# Disable the theming app. It requires imagick (which the snap doesn't ship) and
# displays a warning if it's not installed. This way, the warning is only shown if
# someone needs and enables the theming app.
run_command "Disabling theming by default" occ app:disable theming
run_command "Disabling theming by default" occ -n app:disable theming

# Technically convert-filecache-bigint should be run under maintenance mode, but
# there really isn't anything to go wrong on a fresh install, and the UX of enabling
# maintenance mode as soon as an admin account is created is awful.
occ db:add-missing-indices --no-interaction
occ db:convert-filecache-bigint --no-interaction
occ -n db:add-missing-indices
occ -n db:convert-filecache-bigint
fi
16 changes: 9 additions & 7 deletions src/nextcloud/bin/setup-nextcloud
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
. "$SNAP/utilities/nextcloud-utilities"
# shellcheck source=src/redis/utilities/redis-utilities
. "$SNAP/utilities/redis-utilities"
# shellcheck source=src/common/utilities/common-utilities
. "$SNAP/utilities/common-utilities"

# Make sure nextcloud directory exists
mkdir -p "$SNAP_COMMON/nextcloud"
Expand Down Expand Up @@ -41,15 +43,15 @@ else
cp -r "$SNAP/htdocs/config/autoconfig.php" "$NEXTCLOUD_CONFIG_DIR/"

# Also make sure we're using Redis for the memcache and file locking.
occ config:system:set redis host --value="$REDIS_SOCKET" --type=string
occ config:system:set redis port --value=0 --type=integer
occ config:system:set memcache.locking --value="\OC\Memcache\Redis" --type=string
occ config:system:set memcache.local --value="\OC\Memcache\Redis" --type=string
occ -n config:system:set redis host --value="$REDIS_SOCKET" --type=string
occ -n config:system:set redis port --value=0 --type=integer
occ -n config:system:set memcache.locking --value="\OC\Memcache\Redis" --type=string
occ -n config:system:set memcache.local --value="\OC\Memcache\Redis" --type=string

# It's possible for the updatenotification app to be installed (see
# https://github.com/nextcloud/nextcloud-snap/issues/838), and it'll
# interfere with the upgrade to v14. Disable it now.
occ app:disable updatenotification
occ -n app:disable updatenotification
fi

# Finally, make sure nextcloud is up to date. The return code of the upgrade
Expand All @@ -61,7 +63,7 @@ fi
# invalid arguments = 4;
# other failure = 5;
echo "Making sure nextcloud is fully upgraded..."
occ upgrade --no-interaction
occ -n upgrade
return_code=$?
if [ $return_code -eq 1 ]; then
echo "Nextcloud is not yet installed-- no upgrade necessary"
Expand All @@ -70,7 +72,7 @@ elif [ $return_code -eq 3 ]; then
elif [ $return_code -ne 0 ]; then
echo "Unable to upgrade Nextcloud. Will try again."
# occ may have left it in maintenance mode, so turn that off
occ maintenance:mode --off
disable_maintenance_mode
sleep 10 # Delaying here so systemd doesn't throttle us
exit 1
fi
2 changes: 1 addition & 1 deletion src/nextcloud/utilities/nextcloud-utilities
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ wait_for_nextcloud_to_be_configured()
nextcloud_is_installed()
{
# Urgh, occ still prints text warnings even with JSON output. Thus fromjson?.
installed="$(occ status --output=json | jq -R 'fromjson? | .installed')"
installed="$(occ -n status --output=json | jq -R 'fromjson? | .installed')"
[ "$installed" = "true" ]
}

Expand Down
7 changes: 2 additions & 5 deletions tests/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ source 'https://rubygems.org'
# Test driver
gem 'capybara'

# Webdriver
gem 'capybara-webkit'

# Create xvfb from ruby
gem 'headless'
# Webdriver for chrome headless
gem 'selenium-webdriver'

# Use nice acceptance tests DSL
gem 'rspec'
Expand Down
34 changes: 17 additions & 17 deletions tests/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
capybara (3.11.0)
capybara (3.18.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
xpath (~> 3.2)
capybara-webkit (1.15.1)
capybara (>= 2.3, < 4.0)
json
childprocess (1.0.1)
rake (< 13.0)
diff-lcs (1.3)
headless (2.3.1)
json (2.1.0)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
mini_portile2 (2.4.0)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
public_suffix (3.0.3)
rack (2.0.6)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (12.3.1)
regexp_parser (1.3.0)
rake (12.3.2)
regexp_parser (1.4.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubyzip (1.2.2)
selenium-webdriver (3.142.0)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
xpath (3.2.0)
nokogiri (~> 1.8)

Expand All @@ -48,10 +49,9 @@ PLATFORMS

DEPENDENCIES
capybara
capybara-webkit
headless
rake
rspec
selenium-webdriver

BUNDLED WITH
1.16.4
2.0.1
95 changes: 49 additions & 46 deletions tests/spec/change_mode_spec.rb
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
require 'net/http'

feature "Change operating mode" do
after(:all) do
set_config mode: "production"
wait_for_nextcloud
end

scenario "production" do
`sudo snap set nextcloud mode=production`
expect($?.to_i).to eq 0
set_config mode: "production"
wait_for_nextcloud

assert_apache_prod_tokens
assert_apache_no_signature
assert_php_no_signature
end
assert_apache_no_signature
assert_php_no_signature
end

scenario "debug" do
`sudo snap set nextcloud mode=debug`
expect($?.to_i).to eq 0
scenario "debug" do
set_config mode: "debug"
wait_for_nextcloud

assert_apache_full_tokens
assert_apache_signature
assert_php_signature
end
assert_apache_signature
assert_php_signature
end

scenario "invalid" do
# This will print to stderr. Redirect so we can capture it easily.
scenario "invalid" do
# This will print to stderr. Redirect so we can capture it easily.
output=`sudo snap set nextcloud mode=invalid 2>&1`
expect($?.to_i).to_not eq 0
expect(output).to include "mode must be either 'debug' or 'production'"
end

protected
protected

def assert_apache_prod_tokens
# Verify that Apache clamps down on the server string and stops sending
# version and OS information.
expect(nextcloud_response["server"]).to eq "Apache"
end
def assert_apache_prod_tokens
# Verify that Apache clamps down on the server string and stops sending
# version and OS information.
expect(nextcloud_response["server"]).to eq "Apache"
end

def assert_apache_full_tokens
# Verify that Apache opens up the server string and sends version and
# OS information.
expect(nextcloud_response["server"]).to match /Apache\/2\.4\.\d+ \(Unix\)/
end
def assert_apache_full_tokens
# Verify that Apache opens up the server string and sends version and
# OS information.
expect(nextcloud_response["server"]).to match /Apache\/2\.4\.\d+ \(Unix\)/
end

def assert_apache_no_signature
# Verify that no signature is shown on e.g. 404 pages
response = nextcloud_response(url: "http://localhost/give-me-a-404")
expect(response.body.downcase).to_not include "apache"
end
def assert_apache_no_signature
# Verify that no signature is shown on e.g. 404 pages
response = nextcloud_response(url: "http://localhost/give-me-a-404")
expect(response.body.downcase).to_not include "apache"
end

def assert_apache_signature
# Verify that a signature is shown on e.g. 404 pages
response = nextcloud_response(url: "http://localhost/give-me-a-404")
expect(response.body.downcase).to include "apache"
end
def assert_apache_signature
# Verify that a signature is shown on e.g. 404 pages
response = nextcloud_response(url: "http://localhost/give-me-a-404")
expect(response.body.downcase).to include "apache"
end

def assert_php_no_signature
# Verify that PHP doesn't add an X-Powered-By header
expect(nextcloud_response.to_hash).to_not include "x-powered-by"
end
def assert_php_no_signature
# Verify that PHP doesn't add an X-Powered-By header
expect(nextcloud_response.to_hash).to_not include "x-powered-by"
end

def assert_php_signature
# Verify that PHP adds an X-Powered-By header
response = nextcloud_response
expect(response.to_hash).to include "x-powered-by"
expect(response["x-powered-by"]).to match /PHP\/7\.2\.\d+/
end
def assert_php_signature
# Verify that PHP adds an X-Powered-By header
response = nextcloud_response
expect(response.to_hash).to include "x-powered-by"
expect(response["x-powered-by"]).to match /PHP\/7\.2\.\d+/
end

def nextcloud_response(url: "http://localhost")
return Net::HTTP.get_response(URI(url))
def nextcloud_response(url: "http://localhost")
return Net::HTTP.get_response(URI(url))
end
end
21 changes: 11 additions & 10 deletions tests/spec/change_php_memory_limit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
feature "Change PHP memory limit" do
after(:all) do
set_config "php.memory-limit": "512M"
wait_for_nextcloud
end

scenario "unlimited" do
`sudo snap set nextcloud php.memory-limit=-1`
expect($?.to_i).to eq 0
set_config "php.memory-limit": -1
wait_for_nextcloud

assert_login

# Also assert that we can change it back to the default
`sudo snap set nextcloud php.memory-limit=128M`
expect($?.to_i).to eq 0
set_config "php.memory-limit": "512M"
wait_for_nextcloud

assert_logged_in
end

scenario "bytes" do
`sudo snap set nextcloud php.memory-limit=536870912`
expect($?.to_i).to eq 0
set_config "php.memory-limit": 536870912
wait_for_nextcloud

assert_login

# Also assert that we can change it back to the default
`sudo snap set nextcloud php.memory-limit=128M`
expect($?.to_i).to eq 0
set_config "php.memory-limit": "512M"
wait_for_nextcloud

assert_logged_in
Expand All @@ -45,11 +46,11 @@ def assert_login
fill_in "User", with: "admin"
fill_in "Password", with: "admin"
click_button "Log in"
expect(page).to have_content "Documents"
expect(page).to have_content "All files"
end

def assert_logged_in
visit "/"
expect(page).to have_content "Documents"
expect(page).to have_content "All files"
end
end

0 comments on commit 8a27bc0

Please sign in to comment.