fat_free_crm 0.12.2 → 0.12.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.
Potentially problematic release.
This version of fat_free_crm might be problematic. Click here for more details.
- checksums.yaml +8 -8
- data/lib/fat_free_crm/secret_token_generator.rb +13 -7
- data/lib/fat_free_crm/version.rb +1 -1
- data/spec/lib/secret_token_generator_spec.rb +40 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjExMTQ1NmMzMTliZTRkMjM5ZjdmMjM0MjJlZmMyNTI4NmMzYzYwZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTNhYTM2YTU5YmRiYzI3MGMwNmNlN2M0NzAxODAxNGZmM2ZjYzZmMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTJlZTcyMDlhMTg3NmRlMTA4OGYzN2RiMmIyYjQzYTYwNjcwYTNlMWU3YmEw
|
10
|
+
MTcxNzdjZTJlNzQ1ODA0YjVlZjY5MTcyYTMxOGM2NTI1Y2VhMTc4YjAwM2Yy
|
11
|
+
MGRiZGM1ZDhkZjQxZjIyNWM0MzMxMmU0YTUzNDU4MWIyMDI2MWI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmRiOTMzYjRmMWJlZmM0MmVlODViODNmY2ZmMGM4Y2RmMDVlMTkzMTIyYTgz
|
14
|
+
MWI0NWNkMTUyNDRiZTc1ODEyYWNkMWMwOWZhZGMxZGJmYjk5NjIwMGVmYzM3
|
15
|
+
YjhjMGJjYTM0N2FiMDEwMjQ0NTI2NmIxZDdjOTUxMmI2ZGM0MTQ=
|
@@ -16,17 +16,19 @@ module FatFreeCRM
|
|
16
16
|
# If there is no secret token defined, we generate one and save it as a setting
|
17
17
|
# If a token has been already been saved, we tell Rails to use it and move on.
|
18
18
|
def setup!
|
19
|
-
if
|
19
|
+
if !token_exists?
|
20
20
|
Rails.logger.info("No secret key defined yet... generating and saving to Setting.secret_token")
|
21
|
-
|
21
|
+
new_token!
|
22
22
|
end
|
23
|
-
|
24
|
-
|
23
|
+
# If db isn't setup yet, token will return nil, provide a randomly generated one for now.
|
24
|
+
FatFreeCRM::Application.config.secret_token = ( token || generate_token )
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
|
29
|
+
def token_exists?
|
30
|
+
Setting.secret_token.present?
|
31
|
+
end
|
30
32
|
|
31
33
|
#
|
32
34
|
# Read the current token from settings
|
@@ -36,12 +38,16 @@ module FatFreeCRM
|
|
36
38
|
|
37
39
|
#
|
38
40
|
# Create a new secret token and save it as a setting.
|
39
|
-
def
|
41
|
+
def new_token!
|
40
42
|
quietly do
|
41
|
-
Setting.secret_token =
|
43
|
+
Setting.secret_token = generate_token
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
47
|
+
def generate_token
|
48
|
+
SecureRandom.hex(64)
|
49
|
+
end
|
50
|
+
|
45
51
|
#
|
46
52
|
# Yields to a block that executes with the logging turned off
|
47
53
|
# This stops the secret token from being appended to the log
|
data/lib/fat_free_crm/version.rb
CHANGED
@@ -13,22 +13,37 @@ describe FatFreeCRM::SecretTokenGenerator do
|
|
13
13
|
|
14
14
|
describe "setup!" do
|
15
15
|
|
16
|
-
it "should not generate a token if one
|
17
|
-
FatFreeCRM::SecretTokenGenerator.stub(:
|
18
|
-
|
19
|
-
FatFreeCRM::Application.config.stub(:secret_token).and_return(token)
|
16
|
+
it "should not generate a new token if one exists" do
|
17
|
+
FatFreeCRM::SecretTokenGenerator.stub(:token_exists?).and_return(true)
|
18
|
+
FatFreeCRM::SecretTokenGenerator.should_not_receive(:new_token!)
|
20
19
|
FatFreeCRM::SecretTokenGenerator.setup!
|
21
20
|
end
|
22
21
|
|
23
|
-
it "should generate a token if none exists
|
24
|
-
FatFreeCRM::SecretTokenGenerator.stub(:
|
25
|
-
|
22
|
+
it "should generate a token if none exists" do
|
23
|
+
FatFreeCRM::SecretTokenGenerator.stub(:token_exists?).and_return(false)
|
24
|
+
FatFreeCRM::SecretTokenGenerator.should_receive(:new_token!)
|
26
25
|
FatFreeCRM::SecretTokenGenerator.setup!
|
27
26
|
end
|
28
27
|
|
29
|
-
it "should
|
30
|
-
FatFreeCRM::SecretTokenGenerator.stub(:
|
31
|
-
|
28
|
+
it "should generate a random token if not persisted" do
|
29
|
+
FatFreeCRM::SecretTokenGenerator.stub(:token_exists?).and_return(false)
|
30
|
+
FatFreeCRM::SecretTokenGenerator.stub(:new_token)
|
31
|
+
FatFreeCRM::SecretTokenGenerator.should_receive(:generate_token).exactly(:twice)
|
32
|
+
FatFreeCRM::SecretTokenGenerator.setup!
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "token_exists?" do
|
38
|
+
|
39
|
+
it "should be true" do
|
40
|
+
Setting.stub(:secret_token).and_return(token)
|
41
|
+
FatFreeCRM::SecretTokenGenerator.send(:token_exists?).should eql(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be false" do
|
45
|
+
Setting.stub(:secret_token).and_return(nil)
|
46
|
+
FatFreeCRM::SecretTokenGenerator.send(:token_exists?).should eql(false)
|
32
47
|
end
|
33
48
|
|
34
49
|
end
|
@@ -36,18 +51,27 @@ describe FatFreeCRM::SecretTokenGenerator do
|
|
36
51
|
describe "token" do
|
37
52
|
|
38
53
|
it "should delegate to Setting" do
|
39
|
-
|
40
|
-
|
54
|
+
Setting.should_receive(:secret_token).and_return(token)
|
55
|
+
FatFreeCRM::SecretTokenGenerator.send(:token).should eql(token)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "new_token!" do
|
61
|
+
|
62
|
+
it "should generate and set a new token" do
|
63
|
+
FatFreeCRM::SecretTokenGenerator.should_receive(:generate_token).and_return(token)
|
64
|
+
Setting.should_receive(:secret_token=).with(token)
|
65
|
+
FatFreeCRM::SecretTokenGenerator.send(:new_token!)
|
41
66
|
end
|
42
67
|
|
43
68
|
end
|
44
69
|
|
45
|
-
describe "
|
70
|
+
describe "generate_token!" do
|
46
71
|
|
47
72
|
it "should generate a random token" do
|
48
|
-
|
49
|
-
|
50
|
-
FatFreeCRM::SecretTokenGenerator.send(:generate_and_persist_token!)
|
73
|
+
SecureRandom.should_receive(:hex).with(64).and_return(token)
|
74
|
+
FatFreeCRM::SecretTokenGenerator.send(:generate_token)
|
51
75
|
end
|
52
76
|
|
53
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_free_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Dvorkin
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-01-
|
14
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|