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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODc2YTUzOGEyMTQyYjM2YjU5NjBhZWIxZjdlYzM3YmU0ZDA2MmRiOA==
4
+ YjExMTQ1NmMzMTliZTRkMjM5ZjdmMjM0MjJlZmMyNTI4NmMzYzYwZA==
5
5
  data.tar.gz: !binary |-
6
- Y2Q5ZGRmY2YxZTYzNzBkYjJhMmJkODliODYxZDQwOTZkYWI1ZmYzOA==
6
+ YTNhYTM2YTU5YmRiYzI3MGMwNmNlN2M0NzAxODAxNGZmM2ZjYzZmMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjc1M2JhOGYyNWJhODdlNDVkM2Y1YmU4Yjg2MzlmZmNhNTY4MzUzN2I1NmNk
10
- NDBiNTcyZjNlY2Y3NTBlODM1OThhMTYyZmNkZjIyYTA4ZmIwYzI4OTFiNmYx
11
- NjIwODkzYjQ1ZGQwNDFlMDFlZmJkMDg0Zjk0MTJhNzY3ZjY0NzI=
9
+ YTJlZTcyMDlhMTg3NmRlMTA4OGYzN2RiMmIyYjQzYTYwNjcwYTNlMWU3YmEw
10
+ MTcxNzdjZTJlNzQ1ODA0YjVlZjY5MTcyYTMxOGM2NTI1Y2VhMTc4YjAwM2Yy
11
+ MGRiZGM1ZDhkZjQxZjIyNWM0MzMxMmU0YTUzNDU4MWIyMDI2MWI=
12
12
  data.tar.gz: !binary |-
13
- ZTk3Zjc2MmFmZjU3OGQzNWM1ZTUxOWIyNWRjN2I0Y2ZlZTM5ODA4YWZiZGQ1
14
- YjEwMzBmYzQ2MWExYTBjMWY2OTEzZTVmYjIwZDQ0MDMwZTkwYjcxMTk3NzJl
15
- MjQ0NWUxYmZhZDQ4ZTEwNzU4ZWM0OTYzOWZmMDMyMzRlMTdjNzc=
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 token.blank?
19
+ if !token_exists?
20
20
  Rails.logger.info("No secret key defined yet... generating and saving to Setting.secret_token")
21
- generate_and_persist_token!
21
+ new_token!
22
22
  end
23
- FatFreeCRM::Application.config.secret_token = token
24
- raise(FAIL_MESSAGE) if FatFreeCRM::Application.config.secret_token.blank?
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
- FAIL_MESSAGE = ::I18n.t('secret_token_generator.fail_message', default: "There was a problem generating the secret token. Please see lib/fat_free_crm/secret_token_generator.rb")
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 generate_and_persist_token!
41
+ def new_token!
40
42
  quietly do
41
- Setting.secret_token = SecureRandom.hex(64)
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
@@ -7,7 +7,7 @@ module FatFreeCRM
7
7
  module VERSION #:nodoc:
8
8
  MAJOR = 0
9
9
  MINOR = 12
10
- TINY = 2
10
+ TINY = 3
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -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 already exists" do
17
- FatFreeCRM::SecretTokenGenerator.stub(:token).and_return(nil)
18
- expect(FatFreeCRM::SecretTokenGenerator).to receive(:generate_and_persist_token!)
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 already" do
24
- FatFreeCRM::SecretTokenGenerator.stub(:token).and_return(token)
25
- expect(FatFreeCRM::SecretTokenGenerator).not_to receive(:generate_and_persist_token!)
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 raise an error if the token is still blank (should never happen)" do
30
- FatFreeCRM::SecretTokenGenerator.stub(:token).and_return(nil)
31
- lambda { FatFreeCRM::SecretTokenGenerator.setup! }.should raise_error(RuntimeError)
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
- expect(Setting).to receive(:secret_token).and_return(token)
40
- expect(FatFreeCRM::SecretTokenGenerator.send(:token)).to eql(token)
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 "generate_and_persist_token!" do
70
+ describe "generate_token!" do
46
71
 
47
72
  it "should generate a random token" do
48
- expect(SecureRandom).to receive(:hex).with(64).and_return(token)
49
- expect(Setting).to receive(:secret_token=).with(token)
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.2
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-07 00:00:00.000000000 Z
14
+ date: 2014-01-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails