bunto-auth 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+
3
+ describe "strategies" do
4
+ class TestHelper
5
+ include BuntoAuth::Helpers
6
+
7
+ def initialize(path = nil)
8
+ @path = path
9
+ end
10
+
11
+ def request
12
+ Rack::Request.new("PATH_INFO" => @path)
13
+ end
14
+ end
15
+
16
+ before(:each) do
17
+ BuntoAuth.instance_variable_set("@config", nil)
18
+ @helper = TestHelper.new
19
+ ENV["GITHUB_ORG_NAME"] = nil
20
+ ENV["GITHUB_TEAM_ID"] = nil
21
+ ENV["GITHUB_TEAMS_ID"] = nil
22
+ end
23
+
24
+ it "should return nil if no ID is set" do
25
+ expect(@helper.authentication_strategy).to eql(nil)
26
+ end
27
+
28
+ it "should detect the org strategy" do
29
+ with_env("GITHUB_ORG_NAME", "some_org") do
30
+ expect(@helper.authentication_strategy).to eql(:org)
31
+ end
32
+ end
33
+
34
+ it "should detect the team strategy" do
35
+ with_env("GITHUB_TEAM_ID", "1234") do
36
+ expect(@helper.authentication_strategy).to eql(:team)
37
+ end
38
+ end
39
+
40
+ it "should detect the teams strategy" do
41
+ with_env("GITHUB_TEAM_IDS", "1234,5678") do
42
+ expect(@helper.authentication_strategy).to eql(:teams)
43
+ end
44
+ end
45
+
46
+ it "should know if a path is whitelisted" do
47
+ File.write(BuntoAuth.config_file, "bunto_auth:\n whitelist:\n - drafts?\n")
48
+
49
+ helper = TestHelper.new("/foo")
50
+ expect(helper.whitelisted?).to eql(false)
51
+
52
+ helper = TestHelper.new("/draft")
53
+ expect(helper.whitelisted?).to eql(true)
54
+ end
55
+
56
+ it "should not err out if there is no whitelist" do
57
+ helper = TestHelper.new("/drafts")
58
+ BuntoAuth.instance_variable_set("@config", {})
59
+ expect(helper.whitelisted?).to eql(false)
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe "BuntoAuth" do
4
+ before(:each) do
5
+ setup_tmp_dir
6
+ BuntoAuth.instance_variable_set("@config", nil)
7
+ end
8
+
9
+ it "should know the config file path" do
10
+ expected = File.expand_path "tmp/_config.yml", base_dir
11
+ expect(BuntoAuth.config_file).to eql(expected)
12
+ end
13
+
14
+ it "should return a null hash if no config file exists" do
15
+ expect(BuntoAuth.config).to eql({})
16
+ end
17
+
18
+ it "should return a null hash if config file doesn't contain bunto_auth" do
19
+ File.write(BuntoAuth.config_file, "foo: bar\n")
20
+ expect(BuntoAuth.config).to eql({})
21
+ end
22
+
23
+ it "should return the config hash if the config files contains bunto_auth" do
24
+ File.write(BuntoAuth.config_file, "bunto_auth:\n ssl: true\n whitelist:\n - drafts?\n")
25
+ expect(BuntoAuth.config).to eql("ssl" => true, "whitelist" => ["drafts?"])
26
+ end
27
+
28
+ it "should disable ssl by default" do
29
+ expect(BuntoAuth.ssl?).to eql(false)
30
+ end
31
+
32
+ it "should know when ssl is requested" do
33
+ File.write(BuntoAuth.config_file, "bunto_auth:\n ssl:true\n")
34
+ expect(BuntoAuth.ssl?).to eql(true)
35
+ end
36
+
37
+ it "should know when ssl is disabled" do
38
+ File.write(BuntoAuth.config_file, "bunto_auth:\n ssl:false\n")
39
+ expect(BuntoAuth.ssl?).to eql(true)
40
+ end
41
+
42
+ it "should parse the whitelist" do
43
+ File.write(BuntoAuth.config_file, "bunto_auth:\n whitelist:\n - drafts?\n")
44
+ expect(BuntoAuth.whitelist).to eql(%r!drafts?!)
45
+ end
46
+ end
@@ -0,0 +1,62 @@
1
+ require "bundler/setup"
2
+ require "fileutils"
3
+
4
+ ENV["RACK_ENV"] = "test"
5
+ $LOAD_PATH.push File.join(File.dirname(__FILE__), "..", "lib")
6
+
7
+ require "rack/test"
8
+ require "sinatra/auth/github"
9
+ require "sinatra/auth/github/test/test_helper"
10
+ require "webmock/rspec"
11
+ require "dotenv"
12
+ require "open3"
13
+
14
+ def base_dir
15
+ File.expand_path "../", File.dirname(__FILE__)
16
+ end
17
+
18
+ def tmp_dir
19
+ File.expand_path "tmp", base_dir
20
+ end
21
+
22
+ def bin_path
23
+ File.expand_path "./bin/bunto-auth", base_dir
24
+ end
25
+
26
+ def tear_down_tmp_dir
27
+ FileUtils.rm_rf tmp_dir
28
+ end
29
+
30
+ def setup_tmp_dir
31
+ tear_down_tmp_dir
32
+ FileUtils.mkdir tmp_dir
33
+ File.write File.expand_path("index.html", tmp_dir), "My awesome site"
34
+ FileUtils.mkdir "#{tmp_dir}/some_dir"
35
+ File.write File.expand_path("some_dir/index.html", tmp_dir), "My awesome directory"
36
+ Dir.chdir tmp_dir
37
+ end
38
+
39
+ def with_env(key, value)
40
+ old_env = ENV[key]
41
+ ENV[key] = value
42
+ yield
43
+ ENV[key] = old_env
44
+ end
45
+
46
+ def execute_bin(env, *args)
47
+ output, status = Open3.capture2e(env, bin_path, *args)
48
+ raise "Command `#{bin_path} #{args.join(" ")}` failed: #{output}" if status != 0
49
+ output
50
+ end
51
+
52
+ Dotenv.load
53
+ ENV["GITHUB_CLIENT_ID"] ||= "IGNORE"
54
+ ENV["GITHUB_CLIENT_SECRET"] ||= "IGNORE"
55
+ setup_tmp_dir
56
+
57
+ require_relative "../lib/bunto-auth"
58
+ WebMock.disable_net_connect!
59
+
60
+ RSpec.configure do |config|
61
+ config.include(Sinatra::Auth::Github::Test::Helper)
62
+ end
@@ -0,0 +1,3 @@
1
+ _site
2
+ .env
3
+ /Gemfile.lock
@@ -0,0 +1,9 @@
1
+ # This file is auto-generated by Bunto Auth
2
+ # Feel free to add additional Rake tasks so long as
3
+ # `rake assets:precompile` continues to generate the bunto site
4
+
5
+ namespace :assets do
6
+ task :precompile do
7
+ sh 'bundle exec bunto-auth build'
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # This file is auto-generated by Bunto Auth
2
+ # It tells Heroku how to launch our site
3
+
4
+ require 'bunto-auth'
5
+ run BuntoAuth.site
@@ -0,0 +1,19 @@
1
+ <html>
2
+ <head>
3
+ <title>It Worked!</title>
4
+ <style>
5
+ img {
6
+ width: 500;
7
+ }
8
+ body {
9
+ text-align: center;
10
+ font-size: 1.5em;
11
+ }
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <h1>Great Scott, it Worked!</h1>
16
+ <img src="https://octodex.github.com/images/doctocat-brown.jpg"/>
17
+ <p><em>Hint:</em> If you're seeing this page, that means you're authenticated</p>
18
+ </body>
19
+ </html>
metadata ADDED
@@ -0,0 +1,307 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunto-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Balter
8
+ - Suriyaa Kudo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bunto
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 3.2.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 3.2.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: sinatra-index
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: sinatra_auth_github
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rack
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.6'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.6'
70
+ - !ruby/object:Gem::Dependency
71
+ name: dotenv
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '2.0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '2.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '10.3'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '10.3'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rack-ssl-enforcer
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.2'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.2'
112
+ - !ruby/object:Gem::Dependency
113
+ name: mercenary
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '0.3'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '0.3'
126
+ - !ruby/object:Gem::Dependency
127
+ name: safe_yaml
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '1.0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: colorator
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1.0'
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '1.0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: activesupport
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '4.0'
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '4.0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: rspec
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '3.1'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '3.1'
182
+ - !ruby/object:Gem::Dependency
183
+ name: rack-test
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.6'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '0.6'
196
+ - !ruby/object:Gem::Dependency
197
+ name: webmock
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: '1.2'
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: '1.2'
210
+ - !ruby/object:Gem::Dependency
211
+ name: pry
212
+ requirement: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - "~>"
215
+ - !ruby/object:Gem::Version
216
+ version: '0.10'
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - "~>"
222
+ - !ruby/object:Gem::Version
223
+ version: '0.10'
224
+ - !ruby/object:Gem::Dependency
225
+ name: rubocop
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - "~>"
229
+ - !ruby/object:Gem::Version
230
+ version: '0.35'
231
+ type: :development
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - "~>"
236
+ - !ruby/object:Gem::Version
237
+ version: '0.35'
238
+ description: A simple way to use GitHub OAuth to serve a protected Bunto site to your
239
+ GitHub organization.
240
+ email:
241
+ - ben@balter.com
242
+ - suriyaa@bunto.tk
243
+ executables:
244
+ - bunto-auth
245
+ extensions: []
246
+ extra_rdoc_files: []
247
+ files:
248
+ - ".gitignore"
249
+ - ".rubocop.yml"
250
+ - ".travis.yml"
251
+ - Gemfile
252
+ - README.md
253
+ - Rakefile
254
+ - bin/bunto-auth
255
+ - bunto-auth.gemspec
256
+ - lib/bunto-auth.rb
257
+ - lib/bunto_auth/auth_site.rb
258
+ - lib/bunto_auth/bunto_site.rb
259
+ - lib/bunto_auth/commands.rb
260
+ - lib/bunto_auth/config.rb
261
+ - lib/bunto_auth/config_error.rb
262
+ - lib/bunto_auth/helpers.rb
263
+ - lib/bunto_auth/sinatra/auth/github.rb
264
+ - lib/bunto_auth/version.rb
265
+ - script/bootstrap
266
+ - script/cibuild
267
+ - script/console
268
+ - script/release
269
+ - script/server
270
+ - script/setup
271
+ - spec/bunto_auth_auth_site_spec.rb
272
+ - spec/bunto_auth_bin_spec.rb
273
+ - spec/bunto_auth_bunto_site_spec.rb
274
+ - spec/bunto_auth_commands_spec.rb
275
+ - spec/bunto_auth_helpers_spec.rb
276
+ - spec/bunto_auth_spec.rb
277
+ - spec/spec_helper.rb
278
+ - templates/.gitignore
279
+ - templates/Rakefile
280
+ - templates/config.ru
281
+ - templates/index.html
282
+ homepage: https://github.com/bunto/bunto-auth
283
+ licenses:
284
+ - MIT
285
+ metadata: {}
286
+ post_install_message:
287
+ rdoc_options: []
288
+ require_paths:
289
+ - lib
290
+ required_ruby_version: !ruby/object:Gem::Requirement
291
+ requirements:
292
+ - - ">="
293
+ - !ruby/object:Gem::Version
294
+ version: '0'
295
+ required_rubygems_version: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ requirements: []
301
+ rubyforge_project:
302
+ rubygems_version: 2.6.8
303
+ signing_key:
304
+ specification_version: 4
305
+ summary: A simple way to use GitHub OAuth to serve a protected Bunto site to your
306
+ GitHub organization
307
+ test_files: []