micropub-server-rails 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00f8d5e92e1544532202c472d40698702c949908
4
- data.tar.gz: 83985b66020fbb74467a53508b71381c9fbce073
3
+ metadata.gz: e0d1797707cb23260c584285b9b401db7e802902
4
+ data.tar.gz: ef87798788f594ea0e26892207ed1a429a450bc8
5
5
  SHA512:
6
- metadata.gz: bd1fd80e419513f3b7a6c47b6f82c76564afb270945af0061bc71e04627ace990327a4d60fc030e29f19e80f7de04cc9b0fb1d81866c5a5a6e6b6ae23f1c2348
7
- data.tar.gz: 58fcadb1e3495fb391a0a9df949a20279fdc1acba0f768989a491ade763b76bd2d0b8b8a327b83805bef248072e953ebd3782b1b8381d18361b0fe9ae6581a94
6
+ metadata.gz: c44ee546e070a5e8025fc93c5ea116d439c96656349ac56a7f56ee1c154dfbf96dc2780829fa389b3ce3b8b5e2a7a0bf4c4b2cfb3ca322ba1769ec03fdc98465
7
+ data.tar.gz: ca8916c1f7381db0199d13acd9ed6a0bbeb90c61971fcbcd18da6eedfa667d2f2da3a2165c3f95c68023eda7635367baa5455c3523bd9869dcf8c872bf1f13d9
@@ -1,11 +1,5 @@
1
1
  require 'micropub'
2
2
 
3
- Micropub.configure do |c|
4
- c.token_endpoint = "https://tokens.indieauth.com/token"
5
- c.me = "http://bookisworthy.com"
6
- c.allowed_scopes = [:post]
7
- end
8
-
9
3
  module Micropub::Server::Rails
10
4
  class Middleware
11
5
  def initialize(app)
@@ -15,28 +9,27 @@ module Micropub::Server::Rails
15
9
  def call(env)
16
10
  if env["PATH_INFO"] == "/micropub"
17
11
  token = Micropub::Token.new(auth_token(env))
18
- puts token.inspect
19
- if token.valid?
20
- response
21
- else
22
- error_response
23
- end
12
+ token.valid? ? response : error_response
24
13
  else
25
14
  @app.call env
26
15
  end
27
16
  end
28
17
 
29
18
  def auth_token(env)
30
- input = env["HTTP_AUTHORIZATION"] || request(env).params[:access_token] || ""
19
+ input = env["HTTP_AUTHORIZATION"] || request(env).params["access_token"] || ""
31
20
  input.split("Bearer ").last
32
21
  end
33
22
 
34
23
  def response
35
- [201, headers, ["I am micropub."]]
24
+ [201, headers, body]
36
25
  end
37
26
 
38
27
  def error_response
39
- [401, {}, [""]]
28
+ [401, {}, body]
29
+ end
30
+
31
+ def body
32
+ [""]
40
33
  end
41
34
 
42
35
  def request(env)
@@ -1,7 +1,7 @@
1
1
  module Micropub
2
2
  module Server
3
3
  module Rails
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  end
7
7
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.8"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rack-test"
24
25
 
25
26
  spec.add_dependency "micropub", "~> 0.0.3"
26
27
  end
@@ -0,0 +1,57 @@
1
+ require "micropub/server/rails/middleware"
2
+ require "rack/test"
3
+
4
+ Micropub.configure do |c|
5
+ c.token_endpoint = "https://tokens.indieauth.com/token"
6
+ c.me = "http://bookisworthy.com"
7
+ c.allowed_scopes = [:post]
8
+ end
9
+
10
+ describe Micropub::Server::Rails::Middleware do
11
+ include Rack::Test::Methods
12
+ let(:rails) { double("rails") }
13
+ def app
14
+ Micropub::Server::Rails::Middleware.new(rails)
15
+ end
16
+
17
+ describe "invalid route" do
18
+ it "calls `call` on parent app" do
19
+ expect(rails).to receive(:call).and_return [200, {}, [""]]
20
+ get "/"
21
+ end
22
+ end
23
+
24
+ describe "POST /micropub" do
25
+ before do
26
+ expect(Micropub::Token).to receive(:new).with("1234").and_return(token)
27
+ end
28
+ context "when given a valid token" do
29
+ let(:token) { double("Token", valid?: true) }
30
+
31
+ it "returns a 201" do
32
+ post "/micropub", {}, "HTTP_AUTHORIZATION" => "Bearer 1234"
33
+ expect(last_response.status).to eq 201
34
+ end
35
+
36
+ it "returns a Location header" do
37
+ post "/micropub", {}, "HTTP_AUTHORIZATION" => "Bearer 1234"
38
+ expect(last_response.header["Location"]).to eq "http://bookisworthy.com/posts/1"
39
+ end
40
+
41
+ it "with params access_token returns a 201" do
42
+ post "/micropub", {access_token: 1234}
43
+ expect(last_response.status).to eq 201
44
+ end
45
+
46
+ end
47
+
48
+ context "when given an invalid token" do
49
+ let(:token) { double("Token", valid?: false) }
50
+
51
+ it "returns a 401" do
52
+ post "/micropub", {}, "HTTP_AUTHORIZATION" => "Bearer 1234"
53
+ expect(last_response.status).to eq 401
54
+ end
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micropub-server-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Becker
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rack-test
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: micropub
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +104,7 @@ files:
90
104
  - lib/micropub/server/rails/railtie.rb
91
105
  - lib/micropub/server/rails/version.rb
92
106
  - micropub-server-rails.gemspec
107
+ - spec/lib/micropub/server/rails/middleware_spec.rb
93
108
  homepage:
94
109
  licenses:
95
110
  - Public Domain, CC0
@@ -114,4 +129,5 @@ rubygems_version: 2.4.5
114
129
  signing_key:
115
130
  specification_version: 4
116
131
  summary: Micropub Railtie
117
- test_files: []
132
+ test_files:
133
+ - spec/lib/micropub/server/rails/middleware_spec.rb