|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'passbolt_api service' do |
| 4 | + |
| 5 | + before(:all) do |
| 6 | + @mysql_image = Docker::Image.create('fromImage' => 'mariadb:latest') |
| 7 | + @mysql = Docker::Container.create( |
| 8 | + 'Env' => [ |
| 9 | + 'MYSQL_ROOT_PASSWORD=test', |
| 10 | + 'MYSQL_DATABASE=passbolt', |
| 11 | + 'MYSQL_USER=passbolt', |
| 12 | + 'MYSQL_PASSWORD=±!@#$%^&*()_+=-}{|:;<>?' |
| 13 | + ], |
| 14 | + "Healthcheck" => { |
| 15 | + "Test": [ |
| 16 | + "CMD-SHELL", |
| 17 | + "mysqladmin ping --silent" |
| 18 | + ] |
| 19 | + }, |
| 20 | + 'Image' => @mysql_image.id) |
| 21 | + @mysql.start |
| 22 | + |
| 23 | + while @mysql.json['State']['Health']['Status'] != 'healthy' |
| 24 | + sleep 1 |
| 25 | + end |
| 26 | + |
| 27 | + @image = Docker::Image.build_from_dir(ROOT_DOCKERFILES) |
| 28 | + |
| 29 | + @container = Docker::Container.create( |
| 30 | + 'Env' => [ |
| 31 | + "DATASOURCES_DEFAULT_HOST=#{@mysql.json['NetworkSettings']['IPAddress']}", |
| 32 | + ], |
| 33 | + 'Binds' => [ "#{FIXTURES_PATH + '/passbolt.php'}:/var/www/passbolt/config/passbolt.php" ], |
| 34 | + 'Image' => @image.id) |
| 35 | + |
| 36 | + @container.start |
| 37 | + @container.logs(stdout: true) |
| 38 | + |
| 39 | + set :docker_container, @container.id |
| 40 | + sleep 17 |
| 41 | + end |
| 42 | + |
| 43 | + after(:all) do |
| 44 | + @mysql.kill |
| 45 | + @container.kill |
| 46 | + end |
| 47 | + |
| 48 | + let(:passbolt_host) { @container.json['NetworkSettings']['IPAddress'] } |
| 49 | + let(:uri) { "/healthcheck/status.json" } |
| 50 | + let(:curl) { "curl -sk -o /dev/null -w '%{http_code}' -H 'Host: passbolt.local' https://#{passbolt_host}/#{uri}" } |
| 51 | + |
| 52 | + describe 'php service' do |
| 53 | + it 'is running supervised' do |
| 54 | + expect(service('php-fpm')).to be_running.under('supervisor') |
| 55 | + end |
| 56 | + |
| 57 | + it 'has its port open' do |
| 58 | + expect(@container.json['Config']['ExposedPorts']).to have_key('9000/tcp') |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + describe 'email cron' do |
| 63 | + it 'is running supervised' do |
| 64 | + expect(service('cron')).to be_running.under('supervisor') |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + describe 'web service' do |
| 69 | + it 'is running supervised' do |
| 70 | + expect(service('nginx')).to be_running.under('supervisor') |
| 71 | + end |
| 72 | + |
| 73 | + it 'is listening on port 80' do |
| 74 | + expect(@container.json['Config']['ExposedPorts']).to have_key('80/tcp') |
| 75 | + end |
| 76 | + |
| 77 | + it 'is listening on port 443' do |
| 78 | + expect(@container.json['Config']['ExposedPorts']).to have_key('443/tcp') |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + describe 'passbolt status' do |
| 83 | + it 'returns 200' do |
| 84 | + expect(command(curl).stdout).to eq '200' |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + describe 'passbolt serverkey unaccessible' do |
| 89 | + let(:uri) { '/config/gpg/serverkey.asc' } |
| 90 | + it "returns 404" do |
| 91 | + expect(command(curl).stdout).to eq '404' |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | + describe 'passbolt serverkey private unaccessible' do |
| 96 | + let(:uri) { '/config/gpg/serverkey_private.asc' } |
| 97 | + it 'returns 404' do |
| 98 | + expect(command(curl).stdout).to eq '404' |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + describe 'passbolt conf unaccessible' do |
| 103 | + let(:uri) { '/config/app.php' } |
| 104 | + it 'returns 404' do |
| 105 | + expect(command(curl).stdout).to eq '404' |
| 106 | + end |
| 107 | + end |
| 108 | + describe 'passbolt tmp folder is unaccessible' do |
| 109 | + let(:uri) { '/tmp/cache/database/empty' } |
| 110 | + it 'returns 404' do |
| 111 | + expect(command(curl).stdout).to eq '404' |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + describe 'hide information' do |
| 116 | + let(:curl) { "curl -Isk -H 'Host: passbolt.local' https://#{passbolt_host}/" } |
| 117 | + it 'hides php version' do |
| 118 | + expect(command("#{curl} | grep 'X-Powered-By: PHP'").stdout).to be_empty |
| 119 | + end |
| 120 | + |
| 121 | + it 'hides nginx version' do |
| 122 | + expect(command("#{curl} | grep 'Server:'").stdout.strip).to match(/^Server:\s+nginx$/) |
| 123 | + end |
| 124 | + end |
| 125 | + |
| 126 | +end |
0 commit comments