cf-perm-test-helpers 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c5098d775ca87a09c66e1b2c5f35d5627a616c3
4
+ data.tar.gz: e4ac24532aac9085bd6d11a4161dc7267cea5cfc
5
+ SHA512:
6
+ metadata.gz: 7e511820e65a378c729f17584500da42bc15023dab0a89c99a211312ddc04f66744a0d75e54f2a4d55e49794e9e7410ff651c9ad4792297ce80da09618e01d37
7
+ data.tar.gz: e039df1098bf1e9a7a22d417324141d25242cbdb48996ca3f86b6892d9c862b03c97e7e4ca1b73d393e67795ba324f0b7e9396313539ab427cf0ae11e357b948
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
data/NOTICE ADDED
@@ -0,0 +1,15 @@
1
+ perm-rb
2
+
3
+ Copyright (c) 2017 CloudFoundry.org Foundation, Inc. All Rights Reserved.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # Perm Gem
@@ -0,0 +1,22 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDbzCCAlegAwIBAgIUTadXn91P5E0yWFHz8uKTkkgzZ2MwDQYJKoZIhvcNAQEL
3
+ BQAwEjEQMA4GA1UEAwwHcGVybS1jYTAeFw0xNzA5MjgyMTM0MjZaFw0yNzA5MjYy
4
+ MTM0MjZaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQAD
5
+ ggEPADCCAQoCggEBAPsA/65ee9JgHs8+T/rvxUF5PDzQrO2sm+wSU/BKbWN9MFcR
6
+ IRueTLhSG20C1ZU51g2aGQaPlX0mHMjmrVuj+bqcQvedFPiyfXyfzwHZuZLofH4P
7
+ rLJ6Cnn4oUEboLa3te2dVd8qQqHD8F98vKbpjhyPVbp6DbEmw+/VqBwmdLdX+uTe
8
+ myzxsxSuvgdfowSFt5tPU8s7XySqnbAHkjxRAL2Y+e8jlnEUjHAaQi87c8JsdnM/
9
+ P0I+qS0mbHU2gZHoK7kbx5oeTPhCj1UPmiMe3cC7jZS61MNnQEQ4cdZM3xZrv2hT
10
+ iILtuI6mP5Yepx9Chdnxw0FaoC8PButZzTsusZECAwEAAaOBujCBtzAdBgNVHQ4E
11
+ FgQU/gPT7uM6aLH/bTFtfMeHtCxHN2MwGgYDVR0RBBMwEYI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1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBANaZaQsCBFxb
14
+ t9YMRUAmosOZ0iN04NRH3YydaWIf5mEQN8AlkCGBwcHujf26+k9fsevgAs6yK6ku
15
+ fpet6ZhlZBUJK+bCPvN9q5CSDrXHe5J7i/Sadh2bKJ7PplngyD6gnGk5HGJdGt5m
16
+ c9TE+i1oVdr4armUPtVunfRII5GF/T+KJIk1578HYPobXvNZUriG5Te+NJ5AoPP1
17
+ HagFePCC73xEdIJUxPsSILhRCU5+Zync3n/8PxF9lMFmngElPMqpm6a/8jSqXNs0
18
+ 02tYCqRZxkDunXQxiQWPdPvH4Le0aw1FqZTx9Fgoa+Sy1PjRoCIaOim1/MlAugUZ
19
+ FtJ142A5d3I=
20
+ -----END CERTIFICATE-----
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'perm_test_helpers/version'
4
+ require 'perm_test_helpers/server_runner'
@@ -0,0 +1,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mysql'
4
+ require 'securerandom'
5
+ require 'socket'
6
+ require 'subprocess'
7
+
8
+ module CloudFoundry
9
+ module PermTestHelpers
10
+ # rubocop:disable Metrics/ClassLength
11
+ class ServerRunner
12
+ attr_reader :hostname, :port, :tls_ca, :tls_ca_path
13
+
14
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
15
+ def initialize(opts = {})
16
+ cwd = File.dirname(__FILE__)
17
+ cert_path = File.join(cwd, '..', 'fixtures', 'certs')
18
+
19
+ @hostname = opts[:hostname] || ENV['PERM_TEST_HOSTNAME'] || 'localhost'
20
+ @port = opts[:port] || ENV['PERM_TEST_PORT'] || random_port
21
+ @perm_path = opts[:perm_path] || ENV['PERM_TEST_PATH'] || 'perm'
22
+ @log_level = opts[:log_level] || ENV['PERM_TEST_LOG_LEVEL'] || 'fatal'
23
+ @tls_cert = opts[:tls_cert_path] || ENV['PERM_TEST_TLS_CERT_PATH'] || File.join(cert_path, 'tls.crt')
24
+ @tls_key = opts[:tls_key_path] || ENV['PERM_TEST_TLS_KEY_PATH'] || File.join(cert_path, 'tls.key')
25
+ @tls_ca_path = opts[:tls_ca_path] || ENV['PERM_TEST_TLS_CA_PATH'] || File.join(cert_path, 'tls_ca.crt')
26
+ @audit_file_path = opts[:audit_file_path] || ENV['PERM_TEST_AUDIT_FILE_PATH'] || '/dev/null'
27
+ @tls_ca = File.open(tls_ca_path).read
28
+
29
+ opts[:db] ||= {}
30
+ @db_driver = opts[:db][:driver] || ENV['PERM_TEST_SQL_DB_DRIVER'] || 'mysql'
31
+ @db_schema = opts[:db][:schema] || ENV['PERM_TEST_SQL_DB_SCHEMA'] || random_schema
32
+ @db_host = opts[:db][:host] || ENV['PERM_TEST_SQL_DB_HOST'] || 'localhost'
33
+ @db_port = opts[:db][:port] || ENV['PERM_TEST_SQL_DB_PORT'] || '3306'
34
+ @db_socket = opts[:db][:socket] || ENV['PERM_TEST_SQL_DB_SOCKET'] || Mysql::MYSQL_UNIX_PORT
35
+ @db_username = opts[:db][:username] || ENV['PERM_TEST_SQL_DB_USERNAME'] || 'perm'
36
+ @db_password = opts[:db][:password] || ENV['PERM_TEST_SQL_DB_PASSWORD'] || ''
37
+
38
+ @stdout = opts[:stdout] || ENV['PERM_TEST_STDOUT_PATH'] || STDOUT
39
+ @stderr = opts[:stderr] || ENV['PERM_TEST_STDERR_PATH'] || STDERR
40
+ end
41
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
42
+
43
+ def start
44
+ create_db
45
+ migrate_db
46
+ @process ||= start_perm
47
+ end
48
+
49
+ def stop
50
+ drop_db
51
+ @process&.terminate
52
+ @process = nil
53
+ end
54
+
55
+ private
56
+
57
+ attr_writer :port
58
+ attr_reader :perm_path, :log_level, :process, :tls_cert, :tls_key, :audit_file_path
59
+ attr_reader :db_connection, :db_driver, :db_schema, :db_host, :db_port, :db_socket, :db_username, :db_password
60
+ attr_reader :stdout, :stderr
61
+
62
+ def create_db
63
+ @db_connection = Mysql.connect(db_host, db_username, db_password, nil, db_port, db_socket)
64
+
65
+ stmt = @db_connection.prepare("create database #{db_schema}")
66
+ stmt.execute
67
+ end
68
+
69
+ def migrate_db
70
+ cmd = [
71
+ perm_path,
72
+ 'migrate',
73
+ 'up',
74
+ '--log-level', log_level,
75
+ '--sql-db-driver', db_driver,
76
+ '--sql-db-schema', db_schema,
77
+ '--sql-db-host', db_host,
78
+ '--sql-db-port', db_port,
79
+ '--sql-db-username', db_username,
80
+ '--sql-db-password', db_password
81
+ ]
82
+
83
+ Subprocess.check_call(cmd, stdout: stdout, stderr: stderr)
84
+ end
85
+
86
+ def drop_db
87
+ stmt = @db_connection.prepare("drop database #{db_schema}")
88
+ stmt.execute
89
+ end
90
+
91
+ # rubocop:disable Metrics/AbcSize
92
+ def start_perm
93
+ retries = 0
94
+ process = nil
95
+
96
+ begin
97
+ listen_port = port || random_port
98
+ cmd = [
99
+ perm_path,
100
+ 'serve',
101
+ '--listen-hostname', hostname,
102
+ '--listen-port', listen_port.to_s,
103
+ '--log-level', log_level,
104
+ '--tls-certificate', tls_cert,
105
+ '--tls-key', tls_key,
106
+ '--sql-db-driver', db_driver,
107
+ '--sql-db-schema', db_schema,
108
+ '--sql-db-host', db_host,
109
+ '--sql-db-port', db_port,
110
+ '--sql-db-username', db_username,
111
+ '--sql-db-password', db_password,
112
+ '--audit-file-path', audit_file_path
113
+ ]
114
+
115
+ process = Subprocess.popen(cmd, stdout: stdout, stderr: stderr)
116
+ wait_for_server(process.pid)
117
+ @port = listen_port
118
+
119
+ process
120
+ rescue Errno::ESRCH => e
121
+ # Retry in case the random port is taken
122
+ retries += 1
123
+ process.terminate
124
+
125
+ retry if retries < 3
126
+ raise e
127
+ rescue Errno::ENOENT
128
+ raise 'perm_path must point to server executable'
129
+ end
130
+ end
131
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
132
+
133
+ def random_schema
134
+ # Dashes are invalid in DB names
135
+ "perm-#{SecureRandom.uuid}".tr('-', '_')
136
+ end
137
+
138
+ def random_port
139
+ rand(65_000 - 1024) + 1024
140
+ end
141
+
142
+ # Wait for the server to actually start accepting connections
143
+ def wait_for_server(pid)
144
+ time_waited = 0
145
+
146
+ begin
147
+ Process.getpgid(pid)
148
+
149
+ TCPSocket.new(hostname, port).close
150
+ rescue Errno::ECONNREFUSED, Errno::EAFNOSUPPORT
151
+ time_waited += 0.1
152
+
153
+ raise 'Perm server not running after 5 seconds' if time_waited >= 5
154
+
155
+ sleep 0.1
156
+ retry
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudFoundry
4
+ module PermTestHelpers
5
+ VERSION = '0.0.2'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cf-perm-test-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - CloudFoundry Permissions Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: subprocess
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-mysql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.9.14
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.9.14
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - NOTICE
49
+ - README.md
50
+ - lib_test_helpers/fixtures/certs/tls.crt
51
+ - lib_test_helpers/fixtures/certs/tls.key
52
+ - lib_test_helpers/fixtures/certs/tls_ca.crt
53
+ - lib_test_helpers/perm_test_helpers.rb
54
+ - lib_test_helpers/perm_test_helpers/server_runner.rb
55
+ - lib_test_helpers/perm_test_helpers/version.rb
56
+ homepage:
57
+ licenses:
58
+ - Apache-2.0
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib_test_helpers
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.13
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Test helpers for CloudFoundry Permissions
80
+ test_files: []