Sha256: 4a6a498ee4664630904c1ad305d5fbd5682df9ad0943235bfbd79b8d42ab58ca

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 KB

Contents

require 'net/ssh'
require 'hybrid_platforms_conductor/test_by_service'

module HybridPlatformsConductor

  module HpcPlugins

    module Test

      # Test that deploy removes root access
      class DeployRemovesRootAccess < TestByService

        # Check my_test_plugin.rb.sample documentation for signature details.
        def test_for_node
          unless @nodes_handler.get_root_access_allowed_of(@node) == 'true'
            @deployer.with_test_provisioned_instance(@config.tests_provisioner_id, @node, environment: 'deploy_removes_root_access', reuse_instance: log_debug?) do |deployer, instance|
              # Check that we can connect with root
              ssh_ok = false
              begin
                Net::SSH.start(instance.ip, 'root', password: 'root_pwd', auth_methods: ['password'], verify_host_key: :never) do |ssh|
                  ssh_ok = ssh.exec!('echo Works').strip == 'Works'
                end
              rescue
              end
              assert_equal ssh_ok, true, 'Root does not have access from the empty image'
              if ssh_ok
                deployer.nbr_retries_on_error = 3
                deployer.deploy_on @node
                # As sshd is certainly being restarted, start and stop the container to reload it.
                deployer.restart @node
                # Check that we can't connect with root
                ssh_ok = false
                begin
                  Net::SSH.start(instance.ip, 'root', password: 'root_pwd', auth_methods: ['password'], verify_host_key: :never) do |ssh|
                    ssh_ok = ssh.exec!('echo Works').strip == 'Works'
                  end
                rescue
                end
                assert_equal ssh_ok, false, 'Root can still connect on the image after deployment'
              end
            end
          end
        end

      end

    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hybrid_platforms_conductor-32.16.3 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.16.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.16.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.16.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.15.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.14.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.13.4 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.13.3 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.13.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.13.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb
hybrid_platforms_conductor-32.13.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb