Class: Gitlab::QA::Component::SAML

Inherits:
Object
  • Object
show all
Includes:
Scenario::Actable
Defined in:
lib/gitlab/qa/component/saml.rb

Constant Summary collapse

SAML_IMAGE =
'jamedjo/test-saml-idp'.freeze
SAML_IMAGE_TAG =
'latest'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializeSAML

Returns a new instance of SAML.



19
20
21
22
23
24
# File 'lib/gitlab/qa/component/saml.rb', line 19

def initialize
  @docker = Docker::Engine.new
  @environment = {}
  @volumes = {}
  @network_aliases = []
end

Instance Attribute Details

#dockerObject (readonly)

Returns the value of attribute docker.



15
16
17
# File 'lib/gitlab/qa/component/saml.rb', line 15

def docker
  @docker
end

#environmentObject

Returns the value of attribute environment.



16
17
18
# File 'lib/gitlab/qa/component/saml.rb', line 16

def environment
  @environment
end

#nameObject



38
39
40
# File 'lib/gitlab/qa/component/saml.rb', line 38

def name
  @name ||= "saml-qa-idp"
end

#networkObject

Returns the value of attribute network.



16
17
18
# File 'lib/gitlab/qa/component/saml.rb', line 16

def network
  @network
end

#volumesObject

Returns the value of attribute volumes.



16
17
18
# File 'lib/gitlab/qa/component/saml.rb', line 16

def volumes
  @volumes
end

Instance Method Details

#add_network_alias(name) ⇒ Object



34
35
36
# File 'lib/gitlab/qa/component/saml.rb', line 34

def add_network_alias(name)
  @network_aliases.push(name)
end

#group_nameObject



46
47
48
# File 'lib/gitlab/qa/component/saml.rb', line 46

def group_name
  @group_name ||= "saml_sso_group-#{SecureRandom.hex(4)}"
end

#hostnameObject



42
43
44
# File 'lib/gitlab/qa/component/saml.rb', line 42

def hostname
  "#{name}.#{network}"
end

#instanceObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/qa/component/saml.rb', line 50

def instance
  raise 'Please provide a block!' unless block_given?

  prepare
  start

  yield self
ensure
  teardown
end

#prepareObject



61
62
63
64
65
66
67
# File 'lib/gitlab/qa/component/saml.rb', line 61

def prepare
  pull

  return if @docker.network_exists?(network)

  @docker.network_create(network)
end

#pullObject



105
106
107
# File 'lib/gitlab/qa/component/saml.rb', line 105

def pull
  @docker.pull(SAML_IMAGE, SAML_IMAGE_TAG)
end

#restartObject

rubocop:enable Metrics/AbcSize



94
95
96
# File 'lib/gitlab/qa/component/saml.rb', line 94

def restart
  @docker.restart(name)
end

#set_assertion_consumer_service(assertion_con_service) ⇒ Object



30
31
32
# File 'lib/gitlab/qa/component/saml.rb', line 30

def set_assertion_consumer_service(assertion_con_service)
  @environment['SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE'] = assertion_con_service
end

#set_entity_id(entity_id) ⇒ Object



26
27
28
# File 'lib/gitlab/qa/component/saml.rb', line 26

def set_entity_id(entity_id)
  @environment['SIMPLESAMLPHP_SP_ENTITY_ID'] = entity_id
end

#set_sandbox_name(sandbox_name) ⇒ Object



109
110
111
# File 'lib/gitlab/qa/component/saml.rb', line 109

def set_sandbox_name(sandbox_name)
  ::Gitlab::QA::Runtime::Env.gitlab_sandbox_name = sandbox_name
end

#set_simple_saml_hostnameObject



113
114
115
# File 'lib/gitlab/qa/component/saml.rb', line 113

def set_simple_saml_hostname
  ::Gitlab::QA::Runtime::Env.simple_saml_hostname = hostname
end

#startObject

rubocop:disable Metrics/AbcSize



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gitlab/qa/component/saml.rb', line 70

def start
  docker.run(SAML_IMAGE, SAML_IMAGE_TAG) do |command|
    command << '-d '
    command << "--name #{name}"
    command << "--net #{network}"
    command << "--hostname #{hostname}"
    command << "--publish 8080:8080"
    command << "--publish 8443:8443"

    @volumes.to_h.each do |to, from|
      command.volume(to, from, 'Z')
    end

    @environment.to_h.each do |key, value|
      command.env(key, value)
    end

    @network_aliases.to_a.each do |network_alias|
      command << "--network-alias #{network_alias}"
    end
  end
end

#teardownObject



98
99
100
101
102
103
# File 'lib/gitlab/qa/component/saml.rb', line 98

def teardown
  raise 'Invalid instance name!' unless name

  @docker.stop(name)
  @docker.remove(name)
end