jekyll-auth 0.6.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ require "spec_helper"
2
+
3
+ describe "commands" do
4
+
5
+ before do
6
+ setup_tmp_dir
7
+ end
8
+
9
+ it "should find the template directory" do
10
+ expect(File.directory?(JekyllAuth::Commands.source)).to eql(true)
11
+ expect(File).to exist("#{JekyllAuth::Commands.source}/config.ru")
12
+ end
13
+
14
+ it "should know the destination directory" do
15
+ expect(JekyllAuth::Commands.destination).to eql(tmp_dir)
16
+ end
17
+
18
+ it "should execute a command" do
19
+ expect(JekyllAuth::Commands.execute_command("ls")).to match(/index\.html/)
20
+ end
21
+
22
+ it "should retrieve a team's ID" do
23
+ stub_request(:get, "https://api.github.com/orgs/batler-test-org/teams?per_page=100").
24
+ to_return(:status => 204, :body => [{:slug => "test-team", :id => 1}])
25
+ expect(JekyllAuth::Commands.team_id("batler-test-org", "test-team")).to eql(1)
26
+ end
27
+
28
+ it "should copy the template files" do
29
+ expect(File).to_not exist("#{tmp_dir}/config.ru")
30
+ JekyllAuth::Commands.copy_templates
31
+ expect(File).to exist("#{tmp_dir}/config.ru")
32
+ expect(File).to exist("#{tmp_dir}/Rakefile")
33
+ expect(File).to exist("#{tmp_dir}/.gitignore")
34
+ end
35
+
36
+ it "should know when a directory's changed" do
37
+ `git init`
38
+ `git add .`
39
+ `git commit -m 'initial commit'`
40
+ expect(JekyllAuth::Commands.changed?).to eql(false)
41
+ `touch config.ru`
42
+ expect(JekyllAuth::Commands.changed?).to eql(true)
43
+ end
44
+
45
+ it "knows when env vars are set" do
46
+ var = "SOME_ENV_VAR"
47
+
48
+ ENV.delete(var)
49
+ expect(JekyllAuth::Commands.env_var_set?(var)).to eql(false)
50
+
51
+ ENV[var] = "bar"
52
+ expect(JekyllAuth::Commands.env_var_set?(var)).to eql(true)
53
+
54
+ ENV[var] = ""
55
+ expect(JekyllAuth::Commands.env_var_set?(var)).to eql(false)
56
+
57
+ ENV[var] = nil
58
+ expect(JekyllAuth::Commands.env_var_set?(var)).to eql(false)
59
+ end
60
+
61
+ it "knows when there's a heroku remote" do
62
+ `git init`
63
+ expect(JekyllAuth::Commands.heroku_remote_set?).to eql(false)
64
+ `git remote add heroku https://example.com`
65
+ expect(JekyllAuth::Commands.heroku_remote_set?).to eql(true)
66
+ end
67
+
68
+ it "should make an initial commit" do
69
+ `git init`
70
+ `touch foo.md`
71
+ `git add foo.md`
72
+ JekyllAuth::Commands.initial_commit
73
+ output = JekyllAuth::Commands.execute_command "git", "log"
74
+ expect(output).to match(/\[Jekyll Auth\] Initial setup/)
75
+ end
76
+ end
@@ -0,0 +1,62 @@
1
+ require "spec_helper"
2
+
3
+ describe "strategies" do
4
+
5
+ class TestHelper
6
+ include JekyllAuth::Helpers
7
+
8
+ def initialize(path=nil)
9
+ @path = path
10
+ end
11
+
12
+ def request
13
+ Rack::Request.new("PATH_INFO" => @path)
14
+ end
15
+ end
16
+
17
+ before(:each) do
18
+ JekyllAuth.instance_variable_set("@config", nil)
19
+ @helper = TestHelper.new
20
+ ENV["GITHUB_ORG_ID"] = nil
21
+ ENV["GITHUB_TEAM_ID"] = nil
22
+ ENV["GITHUB_TEAMS_ID"] = nil
23
+ end
24
+
25
+ it "should return nil if no ID is set" do
26
+ expect(@helper.authentication_strategy).to eql(nil)
27
+ end
28
+
29
+ it "should detect the org strategy" do
30
+ with_env("GITHUB_ORG_ID", "some_org") do
31
+ expect(@helper.authentication_strategy).to eql(:org)
32
+ end
33
+ end
34
+
35
+ it "should detect the team strategy" do
36
+ with_env("GITHUB_TEAM_ID", "1234") do
37
+ expect(@helper.authentication_strategy).to eql(:team)
38
+ end
39
+ end
40
+
41
+ it "should detect the teams strategy" do
42
+ with_env("GITHUB_TEAM_IDS", "1234,5678") do
43
+ expect(@helper.authentication_strategy).to eql(:teams)
44
+ end
45
+ end
46
+
47
+ it "should know if a path is whitelisted" do
48
+ File.write(JekyllAuth.config_file, "jekyll_auth:\n whitelist:\n - drafts?\n")
49
+
50
+ helper = TestHelper.new("/foo")
51
+ expect(helper.whitelisted?).to eql(false)
52
+
53
+ helper = TestHelper.new("/draft")
54
+ expect(helper.whitelisted?).to eql(true)
55
+ end
56
+
57
+ it "should not err out if there is no whitelist" do
58
+ helper = TestHelper.new("/drafts")
59
+ JekyllAuth.instance_variable_set("@config", {})
60
+ expect(helper.whitelisted?).to eql(false)
61
+ end
62
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe "jekyll site" do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ JekyllAuth::JekyllSite
8
+ end
9
+
10
+ before do
11
+ setup_tmp_dir
12
+ File.write File.expand_path("_config.yml", tmp_dir), "foo: bar"
13
+ `bundle exec jekyll build`
14
+ end
15
+
16
+ it "serves the index" do
17
+ get "/"
18
+ expect(last_response.body).to eql("My awesome site")
19
+ end
20
+
21
+ it "serves a page" do
22
+ get "/index.html"
23
+ expect(last_response.body).to eql("My awesome site")
24
+ end
25
+
26
+ it "serves a directory index" do
27
+ get "/some_dir"
28
+ expect(last_response.body).to eql("My awesome directory")
29
+ end
30
+
31
+ it "serves the default 404" do
32
+ get "/a-bad-path"
33
+ expect(last_response.status).to eql(404)
34
+ expect(last_response.body).to eql("<h1>Not Found</h1>")
35
+ end
36
+
37
+ it "serves a custom 404" do
38
+ File.write File.expand_path("_site/404.html", tmp_dir), "My custom 404"
39
+ get "/a-bad-path"
40
+ expect(last_response.status).to eql(404)
41
+ expect(last_response.body).to eql("My custom 404")
42
+ end
43
+
44
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe "JekyllAuth" do
4
+
5
+ before(:each) do
6
+ setup_tmp_dir
7
+ JekyllAuth.instance_variable_set("@config",nil)
8
+ end
9
+
10
+ it "should know the config file path" do
11
+ expected = File.expand_path "tmp/_config.yml", base_dir
12
+ expect(JekyllAuth.config_file).to eql(expected)
13
+ end
14
+
15
+ it "should return a null hash if no config file exists" do
16
+ expect(JekyllAuth.config).to eql({})
17
+ end
18
+
19
+ it "should return a null hash if config file doesn't contain jekyll_auth" do
20
+ File.write(JekyllAuth.config_file, "foo: bar\n")
21
+ expect(JekyllAuth.config).to eql({})
22
+ end
23
+
24
+ it "should return the config hash if the config files contains jekyll_auth" do
25
+ File.write(JekyllAuth.config_file, "jekyll_auth:\n ssl: true\n whitelist:\n - drafts?\n")
26
+ expect(JekyllAuth.config).to eql({"ssl"=>true, "whitelist"=>["drafts?"]})
27
+ end
28
+
29
+ it "should disable ssl by default" do
30
+ expect(JekyllAuth.ssl?).to eql(false)
31
+ end
32
+
33
+ it "should know when ssl is requested" do
34
+ File.write(JekyllAuth.config_file, "jekyll_auth:\n ssl:true\n")
35
+ expect(JekyllAuth.ssl?).to eql(true)
36
+ end
37
+
38
+ it "should know when ssl is disabled" do
39
+ File.write(JekyllAuth.config_file, "jekyll_auth:\n ssl:false\n")
40
+ expect(JekyllAuth.ssl?).to eql(true)
41
+ end
42
+
43
+ it "should parse the whitelist" do
44
+ File.write(JekyllAuth.config_file, "jekyll_auth:\n whitelist:\n - drafts?\n")
45
+ expect(JekyllAuth.whitelist).to eql(/drafts?/)
46
+ end
47
+ end
@@ -0,0 +1,60 @@
1
+ require "bundler/setup"
2
+ require 'fileutils'
3
+
4
+ ENV['RACK_ENV'] = 'test'
5
+ $:.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/jekyll-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
+ setup_tmp_dir
54
+
55
+ require_relative "../lib/jekyll-auth"
56
+ WebMock.disable_net_connect!
57
+
58
+ RSpec.configure do |config|
59
+ config.include(Sinatra::Auth::Github::Test::Helper)
60
+ end
@@ -0,0 +1,3 @@
1
+ _site
2
+ .env
3
+ /Gemfile.lock
@@ -0,0 +1,9 @@
1
+ # This file is auto-generated by Jekyll Auth
2
+ # Feel free to add additional Rake tasks so long as
3
+ # `rake assets:precompile` continues to generate the jekyll site
4
+
5
+ namespace :assets do
6
+ task :precompile do
7
+ sh "bundle exec jekyll-auth build"
8
+ end
9
+ end
File without changes
@@ -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="http://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 CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -53,75 +53,75 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: commander
56
+ name: rack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '4.1'
61
+ version: 1.5.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: '4.1'
68
+ version: 1.5.2
69
69
  - !ruby/object:Gem::Dependency
70
- name: git
70
+ name: dotenv
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.2'
75
+ version: '1.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.2'
82
+ version: '1.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: dotenv
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.11'
89
+ version: '10.3'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.11'
96
+ version: '10.3'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rake
98
+ name: rack-ssl-enforcer
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '10.3'
103
+ version: '0.2'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.3'
110
+ version: '0.2'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rack-ssl-enforcer
112
+ name: mercenary
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.2'
117
+ version: '0.3'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.2'
124
+ version: '0.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: safe_yaml
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,76 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: colorator
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rack-test
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.6'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.6'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.2'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.2'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '0.10'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '0.10'
139
209
  description: A simple way to use Github Oauth to serve a protected jekyll site to
140
210
  your GitHub organization.
141
211
  email: ben@balter.com
@@ -145,14 +215,38 @@ extensions: []
145
215
  extra_rdoc_files: []
146
216
  files:
147
217
  - ".gitignore"
218
+ - ".travis.yml"
219
+ - Gemfile
220
+ - README.md
148
221
  - Rakefile
149
222
  - bin/jekyll-auth
150
- - config.ru
223
+ - jekyll-auth.gemspec
151
224
  - lib/jekyll-auth.rb
152
- - lib/jekyll-auth/auth-site.rb
153
- - lib/jekyll-auth/config.rb
154
- - lib/jekyll-auth/jekyll-site.rb
155
- - lib/jekyll-auth/version.rb
225
+ - lib/jekyll_auth/auth_site.rb
226
+ - lib/jekyll_auth/commands.rb
227
+ - lib/jekyll_auth/config_error.rb
228
+ - lib/jekyll_auth/helpers.rb
229
+ - lib/jekyll_auth/jekyll_site.rb
230
+ - lib/jekyll_auth/sinatra/auth/github.rb
231
+ - lib/jekyll_auth/version.rb
232
+ - script/bootstrap
233
+ - script/cibuild
234
+ - script/console
235
+ - script/release
236
+ - script/server
237
+ - script/setup
238
+ - spec/jekyll_auth_auth_site_spec.rb
239
+ - spec/jekyll_auth_bin_spec.rb
240
+ - spec/jekyll_auth_commands_spec.rb
241
+ - spec/jekyll_auth_helpers_spec.rb
242
+ - spec/jekyll_auth_jekyll_site_spec.rb
243
+ - spec/jekyll_auth_spec.rb
244
+ - spec/spec_helper.rb
245
+ - templates/.env
246
+ - templates/.gitignore
247
+ - templates/Rakefile
248
+ - templates/config.ru
249
+ - templates/index.html
156
250
  homepage: https://github.com/benbalter/jekyll-auth
157
251
  licenses:
158
252
  - MIT
@@ -178,4 +272,11 @@ signing_key:
178
272
  specification_version: 4
179
273
  summary: A simple way to use Github OAuth to serve a protected jekyll site to your
180
274
  GitHub organization
181
- test_files: []
275
+ test_files:
276
+ - spec/jekyll_auth_auth_site_spec.rb
277
+ - spec/jekyll_auth_bin_spec.rb
278
+ - spec/jekyll_auth_commands_spec.rb
279
+ - spec/jekyll_auth_helpers_spec.rb
280
+ - spec/jekyll_auth_jekyll_site_spec.rb
281
+ - spec/jekyll_auth_spec.rb
282
+ - spec/spec_helper.rb