cuba-api 0.6.2 → 0.6.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08d01480616570cd7a09d1f5da7a869037be9c2c
4
- data.tar.gz: 6ef17555b198ffac42def04e185ad4033706d4aa
3
+ metadata.gz: 10e2d38b71c73518d8dc210febc45beb6839678e
4
+ data.tar.gz: 3021c0638361a9ec6891a48a34f0aee6d413eef8
5
5
  SHA512:
6
- metadata.gz: 5a71e0b5d9b846a001f6d8d74c723bc9eab62033e82ba7f19dbbb0073d6c8fd2ea2967994578679757db2ef76867cf8b2dfb5e57c078a49f5f20b774ec9243cd
7
- data.tar.gz: 901b16bf0da46243f5007eae69178d4adb84862a17dd2b92654f56891d3ecd6a860b042e98c993439fad92f276e53f60fd35c87a8314375d5fc163a7038c59c7
6
+ metadata.gz: c7e2615360b8c22f90d11d9cc24e0108326b6e9e676da31edc713bbdece45c218cf79d82c4a9486c007d80f5af0db2d1dd27e5d02c379dd905173a8ef73578f3
7
+ data.tar.gz: 6c7676016b48332b795e2640dc899f506c05cd47eff024014ef2bac23ac9cc99ef8e4ff7c41b64aef540bafd97791f18315aa878af7d24f8b1d4f87a63997ecb
data/README.md CHANGED
@@ -5,7 +5,7 @@ cuba-api
5
5
  * [![Dependency Status](https://gemnasium.com/mkristian/cuba-api.png)](https://gemnasium.com/mkristian/cuba-api)
6
6
  * [![Code Climate](https://codeclimate.com/github/mkristian/cuba-api.png)](https://codeclimate.com/github/mkristian/cuba-api)
7
7
 
8
- these are just a handful for [cuba](https://github.com/soveran/cuba) to use cuba as API server.
8
+ these are just a handful plugins for [cuba](https://github.com/soveran/cuba) it as API server.
9
9
 
10
10
  security
11
11
  --------
@@ -31,6 +31,25 @@ require 'cuba_api/aspects/response_status'
31
31
 
32
32
  class CubaAPI < Cuba
33
33
 
34
+ class Response < Cuba::Response
35
+
36
+ def self.new
37
+ Thread.current[ :cuba_api_response ] ||= super
38
+ end
39
+
40
+ def initialize( status = 404,
41
+ headers = { "Content-Type" => "text/plain; charset=utf-8" } )
42
+ super
43
+ end
44
+
45
+ def finish
46
+ Thread.current[ :cuba_api_response ] = nil
47
+ super
48
+ end
49
+ end
50
+
51
+ settings[ :res ] = CubaAPI::Response
52
+
34
53
  plugin CubaApi::Config
35
54
  plugin CubaApi::Loggers
36
55
  plugin CubaApi::Aspects
@@ -22,6 +22,10 @@
22
22
 
23
23
  require 'ixtlan/user_management/guard'
24
24
 
25
+ # TODO move to upstream
26
+ class Ixtlan::UserManagement::GuardException < StandardError
27
+ end
28
+
25
29
  # TODO move to upstream
26
30
  class Ixtlan::UserManagement::Permission
27
31
  attribute :parent, Ixtlan::UserManagement::Permission
@@ -48,7 +52,11 @@ module CubaApi
48
52
  end
49
53
 
50
54
  def current_groups
51
- current_user.groups
55
+ if current_user
56
+ current_user.groups
57
+ else
58
+ []
59
+ end
52
60
  end
53
61
 
54
62
  def allowed_associations
@@ -56,12 +64,18 @@ module CubaApi
56
64
  end
57
65
 
58
66
  def on_context( name, &block )
59
- guard.check_parent( name, guard_context )
60
67
  on name do
61
68
  begin
69
+ guard.check_parent( name, guard_context )
62
70
  old = guard_context
63
71
  guard_context( name )
64
72
  yield( *captures )
73
+ rescue Ixtlan::UserManagement::GuardException
74
+ if respond_to?( :authenticated? ) && authenticated?
75
+ no_body :not_found
76
+ else
77
+ no_body :forbidden
78
+ end
65
79
  ensure
66
80
  guard_context( old )
67
81
  end
@@ -81,7 +81,7 @@ describe CubaApi::Guard do
81
81
 
82
82
  describe 'guarded context with nested context' do
83
83
 
84
- it 'should raise error' do
84
+ it 'should response forbidden' do
85
85
  env = { 'PATH_INFO' => '/users/accounts',
86
86
  'SCRIPT_NAME' => '/users/accounts' }
87
87
 
@@ -94,7 +94,8 @@ describe CubaApi::Guard do
94
94
  end
95
95
 
96
96
  env[ 'REQUEST_METHOD' ] = 'GET'
97
- lambda{ Cuba.call( env ) }.must_raise RuntimeError
97
+ status, _, _ = Cuba.call( env )
98
+ status.must.eq 403
98
99
  end
99
100
 
100
101
  it 'allow all' do
@@ -124,10 +125,9 @@ describe CubaApi::Guard do
124
125
 
125
126
  describe 'guarded context with association' do
126
127
 
127
- let( :env ) do
128
- { 'PATH_INFO' => '/users/42',
129
- 'SCRIPT_NAME' => '/users/42',
130
- }
128
+ before do
129
+ env[ 'PATH_INFO' ] = '/users/42'
130
+ env[ 'SCRIPT_NAME'] = '/users/42'
131
131
  end
132
132
 
133
133
  it 'denies all requests without associated id' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuba-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-13 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cuba