melodiest 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +22 -0
- data/README.md +0 -0
- data/lib/melodiest/auth.rb +19 -0
- data/lib/melodiest/setting.rb +7 -0
- data/lib/melodiest/version.rb +3 -0
- data/lib/melodiest.rb +3 -8
- data/melodiest.gemspec +20 -0
- data/spec/melodiest/auth_spec.rb +27 -0
- data/spec/melodiest/setting_spec.rb +7 -0
- data/spec/melodiest_spec.rb +9 -0
- data/spec/spec_helper.rb +89 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b693bbf15c21036cedd866bf9f5365e35ac350b
|
4
|
+
data.tar.gz: 24d28bd709b712e6d2de7eb5f842944a8f0f69ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 951e0f3dc8f9cd854e8b907c8e7c9d4184e175c6e594cea9d6406c9c7bec1fc6fe3d7eb148f447b255cd55ecccd0f5c091723c5ea9ce0471f762c79d70ac2111
|
7
|
+
data.tar.gz: 454cfcb6cb47a8980852c3899525a6f8d600d50c54555f807ce275dca3bf9831a62f76dbb804475f13826b396b7f914fa2734e8932815641d22eebf28c5d018f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
melodiest (0.1.0)
|
5
|
+
sinatra (= 1.4.5)
|
6
|
+
thin (= 1.6.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
daemons (1.1.9)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
eventmachine (1.0.4)
|
14
|
+
rack (1.6.0)
|
15
|
+
rack-protection (1.5.3)
|
16
|
+
rack
|
17
|
+
rack-test (0.6.3)
|
18
|
+
rack (>= 1.0)
|
19
|
+
rspec (3.1.0)
|
20
|
+
rspec-core (~> 3.1.0)
|
21
|
+
rspec-expectations (~> 3.1.0)
|
22
|
+
rspec-mocks (~> 3.1.0)
|
23
|
+
rspec-core (3.1.7)
|
24
|
+
rspec-support (~> 3.1.0)
|
25
|
+
rspec-expectations (3.1.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.1.0)
|
28
|
+
rspec-mocks (3.1.3)
|
29
|
+
rspec-support (~> 3.1.0)
|
30
|
+
rspec-support (3.1.2)
|
31
|
+
sinatra (1.4.5)
|
32
|
+
rack (~> 1.4)
|
33
|
+
rack-protection (~> 1.4)
|
34
|
+
tilt (~> 1.3, >= 1.3.4)
|
35
|
+
thin (1.6.3)
|
36
|
+
daemons (~> 1.0, >= 1.0.9)
|
37
|
+
eventmachine (~> 1.0)
|
38
|
+
rack (~> 1.0)
|
39
|
+
tilt (1.4.1)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 1.7)
|
46
|
+
melodiest!
|
47
|
+
rack-test (= 0.6.3)
|
48
|
+
rspec (= 3.1.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 kuntoaji
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Melodiest
|
2
|
+
module Auth
|
3
|
+
|
4
|
+
# http://www.sinatrarb.com/faq.html#auth
|
5
|
+
module Http
|
6
|
+
def authorized!(username="admin", password="admin")
|
7
|
+
return if authorized?(username, password)
|
8
|
+
headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
|
9
|
+
halt 401, "Not authorized\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorized?(username, password)
|
13
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
14
|
+
@auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == [username, password]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/melodiest.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'sinatra'
|
2
|
+
require 'melodiest/setting'
|
2
3
|
|
3
4
|
module Melodiest
|
4
|
-
module Config
|
5
|
-
def harmonize_settings
|
6
|
-
set :server, 'thin'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
5
|
class Application < Sinatra::Application
|
11
|
-
extend
|
6
|
+
extend Setting
|
12
7
|
|
13
8
|
configure do
|
14
|
-
|
9
|
+
setup
|
15
10
|
end
|
16
11
|
end
|
17
12
|
end
|
data/melodiest.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'lib/melodiest/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'melodiest'
|
5
|
+
s.version = Melodiest::VERSION
|
6
|
+
s.date = '2015-01-25'
|
7
|
+
s.summary = "Sinatra configuration boilerplate"
|
8
|
+
s.description = "Sinatra configuration boilerplate"
|
9
|
+
s.author = 'Kunto Aji Kristianto'
|
10
|
+
s.email = 'kunto.aji.kr@slackware-id.org'
|
11
|
+
s.files = `git ls-files -z`.split("\x0")
|
12
|
+
s.homepage = 'http://github.com/kuntoaji/melodiest'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.add_development_dependency 'bundler', '~> 1.7'
|
16
|
+
s.add_development_dependency 'rspec', '3.1.0'
|
17
|
+
s.add_development_dependency 'rack-test', '0.6.3'
|
18
|
+
s.add_runtime_dependency 'sinatra', '1.4.5'
|
19
|
+
s.add_runtime_dependency 'thin', '1.6.3'
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative '../../lib/melodiest/auth'
|
2
|
+
|
3
|
+
describe Melodiest::Auth::Http do
|
4
|
+
it "respond to authorized!" do
|
5
|
+
expect(Melodiest::Auth::Http.method_defined?(:authorized!)).to be_truthy
|
6
|
+
end
|
7
|
+
|
8
|
+
it "respond to authorized?" do
|
9
|
+
expect(Melodiest::Auth::Http.method_defined?(:authorized?)).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns 401 status code without authentication" do
|
13
|
+
get "/protected"
|
14
|
+
expect(last_response.status).to eq 401
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns 401 status code with bad authentication" do
|
18
|
+
get "/protected"
|
19
|
+
expect(last_response.status).to eq 401
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns 200 status code with good authentication" do
|
23
|
+
authorize "admin", "admin"
|
24
|
+
get "/protected"
|
25
|
+
expect(last_response.status).to eq 200
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.include Rack::Test::Methods
|
7
|
+
|
8
|
+
# rspec-expectations config goes here. You can use an alternate
|
9
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
10
|
+
# assertions if you prefer.
|
11
|
+
config.expect_with :rspec do |expectations|
|
12
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
13
|
+
# and `failure_message` of custom matchers include text for helper methods
|
14
|
+
# defined using `chain`, e.g.:
|
15
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
16
|
+
# # => "be bigger than 2 and smaller than 4"
|
17
|
+
# ...rather than:
|
18
|
+
# # => "be bigger than 2"
|
19
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
20
|
+
end
|
21
|
+
|
22
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
23
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
24
|
+
config.mock_with :rspec do |mocks|
|
25
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
26
|
+
# a real object. This is generally recommended, and will default to
|
27
|
+
# `true` in RSpec 4.
|
28
|
+
mocks.verify_partial_doubles = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
# These two settings work together to allow you to limit a spec run
|
33
|
+
# to individual examples or groups you care about by tagging them with
|
34
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
35
|
+
# get run.
|
36
|
+
config.filter_run :focus
|
37
|
+
config.run_all_when_everything_filtered = true
|
38
|
+
|
39
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
40
|
+
# For more details, see:
|
41
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
42
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
43
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
44
|
+
#config.disable_monkey_patching!
|
45
|
+
|
46
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
47
|
+
# be too noisy due to issues in dependencies.
|
48
|
+
#config.warnings = true
|
49
|
+
config.warnings = false
|
50
|
+
|
51
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
52
|
+
# file, and it's useful to allow more verbose output when running an
|
53
|
+
# individual spec file.
|
54
|
+
if config.files_to_run.one?
|
55
|
+
# Use the documentation formatter for detailed output,
|
56
|
+
# unless a formatter has already been configured
|
57
|
+
# (e.g. via a command-line flag).
|
58
|
+
config.default_formatter = 'doc'
|
59
|
+
end
|
60
|
+
|
61
|
+
# Print the 10 slowest examples and example groups at the
|
62
|
+
# end of the spec run, to help surface which specs are running
|
63
|
+
# particularly slow.
|
64
|
+
config.profile_examples = 10
|
65
|
+
|
66
|
+
# Run specs in random order to surface order dependencies. If you find an
|
67
|
+
# order dependency and want to debug it, you can fix the order by providing
|
68
|
+
# the seed, which is printed after each run.
|
69
|
+
# --seed 1234
|
70
|
+
config.order = :random
|
71
|
+
|
72
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
73
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
74
|
+
# test failures related to randomization by passing the same `--seed` value
|
75
|
+
# as the one that triggered the failure.
|
76
|
+
Kernel.srand config.seed
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def app
|
81
|
+
Melodiest::Application.helpers Melodiest::Auth::Http
|
82
|
+
|
83
|
+
Melodiest::Application.get "/protected" do
|
84
|
+
authorized!
|
85
|
+
end
|
86
|
+
|
87
|
+
Melodiest::Application
|
88
|
+
end
|
89
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: melodiest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kunto Aji Kristianto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.6.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.6.3
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: sinatra
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +86,21 @@ executables: []
|
|
72
86
|
extensions: []
|
73
87
|
extra_rdoc_files: []
|
74
88
|
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
75
95
|
- lib/melodiest.rb
|
96
|
+
- lib/melodiest/auth.rb
|
97
|
+
- lib/melodiest/setting.rb
|
98
|
+
- lib/melodiest/version.rb
|
99
|
+
- melodiest.gemspec
|
100
|
+
- spec/melodiest/auth_spec.rb
|
101
|
+
- spec/melodiest/setting_spec.rb
|
102
|
+
- spec/melodiest_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
76
104
|
homepage: http://github.com/kuntoaji/melodiest
|
77
105
|
licenses:
|
78
106
|
- MIT
|