leap_salesforce 1.0.5 → 1.2.0

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
  SHA256:
3
- metadata.gz: 50460046dd520df2e2b92b0384733e4b7785109d55f42c88d5dd9c81faad23c0
4
- data.tar.gz: 1124dc04f4dea935ac48e21b1fccfb8b498b6675f1936164087cd35d75152f4d
3
+ metadata.gz: c7d7840f64baf2e945a29ab4f022f5ff2191b3443e9068f9cbd32afafb7520bb
4
+ data.tar.gz: fbe2a1d779b5605cd19c7eb79b2327fb673865170e2becc567bc587fa4d32798
5
5
  SHA512:
6
- metadata.gz: 9674782b9b65f4c60fbac4e376594e7ff626c0a538f1f9e1b3ca745d2905bf9ef420a10f7c93d34ab433304cc3989d9329446efa30e2152923e7d07811f0f42c
7
- data.tar.gz: f35b3686b4404083210e07cf71ab5ec7c21e132e04bb013dc9aadad245c9538f1152037b64995844b3323431e23bb0070f1195083424757377bf09c3b8d72f4f
6
+ metadata.gz: 861290a24fbb1575f0c3338690bd0aef6c65d3ee6a6d0e7a98c5b511e6bffc243891d927b08cd925fa819a09e9b9bcd523a6950729364c5597815f26b8f95bb9
7
+ data.tar.gz: c027b01dc9606cb88d388d25ba3b8895f05c9d5ae47b1377efc42022887b8fa160999c870e078f3434383a1249f24e66951c72b84dcbd5fcaf3398ca22bcd683
data/ChangeLog CHANGED
@@ -1,3 +1,17 @@
1
+ Version 1.2.0
2
+ * Ability to set security token on leap_salesforce user by setting an environment variable with the format
3
+ `ENV["#{key}_token"]``
4
+ * Remove deprecated method of create_enum within soql_settings class
5
+
6
+ Version 1.1.2
7
+ * Fix user_id from session
8
+
9
+ Version 1.1.1
10
+ * Allow session information from SOAP login to be available with LeapSalesforce::Session class
11
+
12
+ Version 1.1.0
13
+ * Proper fix to work with activerecord 7 - requires ruby > 2.7
14
+
1
15
  Version 1.0.5
2
16
  * Fix
3
17
  * Stabilize using of active record by fixing version
data/README.md CHANGED
@@ -104,6 +104,10 @@ Credentials are not stored in stored in source control. They can be setting thro
104
104
  * 'client_secret'
105
105
  * 'password'
106
106
 
107
+ > Security tokens can be set for each user (adding to password in OAuth like in [this article](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm))
108
+ > To do that set an environment variable as USER_KEY_token. E.g, so for a user with a key of :admin
109
+ > the token would be set with the `admin_token` environment variable
110
+
107
111
  Tests can be run using the default `Rake` task.
108
112
 
109
113
  E.g.,
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ RSpec::Core::RakeTask.new(:spec)
14
14
 
15
15
  desc 'Check Salesforce OAuth2 authentication is working'
16
16
  task :check_oauth do
17
+ Soaspec::OAuth2.debug_oauth = true
17
18
  LeapSalesforce.oauth_working?
18
19
  end
19
20
 
data/bin/console CHANGED
@@ -7,6 +7,7 @@ require 'leap_salesforce'
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
- require 'pry'
10
+ require 'irb'
11
+ require 'irb/completion'
11
12
 
12
- Pry.start
13
+ IRB.start(__FILE__)
data/config/general.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Set environment variable to set a security token that will be sent for a user
4
+ # ENV['admin_token'] = 'test'
5
+
3
6
  # Add users to LeapSalesforce context. First user is the default
4
7
  module LeapSalesforce
5
8
  Users.add User.new :admin, 'samuel.garratt@brave-otter-ttxype.com'
data/exe/leap_salesforce CHANGED
@@ -36,6 +36,7 @@ module LeapSalesforce
36
36
  exit if oauth_setup.downcase == 'n'
37
37
  end
38
38
  query_for_parameters # TODO: for sfdx
39
+ has_ignore_file = File.exist?('.gitignore')
39
40
  generate_files binding, ['Gemfile', 'Rakefile', '.leap_salesforce.yml', '.rspec', '.gitignore',
40
41
  { config: ['general.rb', { credentials: 'salesforce_oauth2.yml' }] },
41
42
  { spec: %w[spec_helper.rb limit_spec.rb crud_eg_spec.rb picklists_spec.rb] }]
@@ -52,6 +53,10 @@ module LeapSalesforce
52
53
  puts `rake leaps:create_soql_objects`
53
54
  puts 'Creating enums'.colorize :yellow
54
55
  puts `rake leaps:create_enums`
56
+ return unless has_ignore_file
57
+
58
+ puts 'Your .gitignore is already present so not updated.
59
+ Please ignore "config/credentials/" and "logs/"'.colorize :red
55
60
  end
56
61
  end
57
62
  end
@@ -32,7 +32,7 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
32
32
  spec.add_development_dependency 'semaphore_test_boosters'
33
33
  spec.add_development_dependency 'topoisomerase'
34
34
  spec.add_development_dependency 'yard-doctest'
35
- spec.add_dependency 'activerecord', '6.1'
35
+ spec.add_dependency 'activerecord', '7'
36
36
  spec.add_dependency 'colorize'
37
37
  spec.add_dependency 'factory_bot'
38
38
  spec.add_dependency 'faker', '>= 2.0'
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'nori/core_ext'
4
4
  require 'humanize'
5
+ require 'active_support/isolated_execution_state'
5
6
  require 'active_support/core_ext/string'
6
7
  require 'date'
7
8
  require 'json'
@@ -76,14 +76,13 @@ module LeapSalesforce
76
76
  # using sfdx
77
77
  # @return [Hash] OAuth2 parameters used in connecting to salesforce
78
78
  def oauth_settings
79
- settings = {
80
- username: '<%= LeapSalesforce.api_user %>', password: LeapSalesforce.password,
79
+ {
80
+ username: '<%= LeapSalesforce.api_user %>',
81
+ password: '<%= LeapSalesforce.password + LeapSalesforce.security_token.to_s %>',
81
82
  client_id: LeapSalesforce.client_id,
82
83
  client_secret: LeapSalesforce.client_secret,
83
84
  token_url: "#{LeapSalesforce.general_url}/services/oauth2/token"
84
85
  }
85
- settings[:security_token] = LeapSalesforce.security_token if LeapSalesforce.security_token
86
- settings
87
86
  end
88
87
 
89
88
  # @return [String] General salesforce URL for logging in to
@@ -98,6 +97,8 @@ module LeapSalesforce
98
97
  else
99
98
  LeapSalesforce::Users.where(user)&.username
100
99
  end
100
+ leaps_user = LeapSalesforce::Users.where username: @api_user
101
+ LeapSalesforce.security_token = leaps_user.security_token
101
102
  Soaspec::SpecLogger.info "Using user '#{@api_user}' for API"
102
103
  end
103
104
 
@@ -0,0 +1,41 @@
1
+ require_relative 'auth'
2
+ require 'savon'
3
+ require 'json'
4
+
5
+ module LeapSalesforce
6
+ # Holds information about a login session
7
+ class Session
8
+ # @return [String] Session id returned from SOAP API
9
+ attr_accessor :session_id
10
+ # @return [String] User id returned from SOAP API
11
+ attr_accessor :user_id
12
+ # @return [Hash] Login response
13
+ attr_accessor :login_response
14
+
15
+ def initialize(username, password, security_token = '')
16
+ login_body = LeapSalesforce::Session.soap_login username, password, security_token
17
+
18
+ self.session_id = login_body[:login_response][:result][:session_id]
19
+ self.user_id = login_body[:login_response][:result][:user_id]
20
+ self.login_response = login_body[:login_response]
21
+ end
22
+
23
+ class << self
24
+
25
+ # Login via SOAP API
26
+ def soap_login(username, password, security_token)
27
+ client = Savon.client do
28
+ endpoint "#{SoqlHandler.instance_url}/services/Soap/u/51.0"
29
+ namespace "urn:partner.soap.sforce.com"
30
+ end
31
+
32
+ response = client.call(:login, message:
33
+ {
34
+ username: username,
35
+ password: password + security_token
36
+ })
37
+ response.body
38
+ end
39
+ end
40
+ end
41
+ end
@@ -13,10 +13,4 @@ module SoqlSettings
13
13
  def soql_object_name
14
14
  @soql_object_name || to_s
15
15
  end
16
-
17
- # @deprecated Not used, setting in '.leap_salesforce.yml' controls this now
18
- def create_enum(_set)
19
- LeapSalesforce.logger.warn "Method 'create_enum' called when it is deprecated" \
20
- " from #{caller_locations[0]}"
21
- end
22
16
  end
@@ -14,11 +14,16 @@ module LeapSalesforce
14
14
  # readable format is required such as in a Cucumber test
15
15
  attr_accessor :description
16
16
 
17
- # @param [String, Symbol] key Key used to identify a test user
18
- # @param [String] username Name used to login with user. In email address format.
17
+ # @return [String] Security token of user. Recommend this be set through ENV variable
18
+ attr_accessor :security_token
19
+
20
+ # @param [String, Symbol] user_params[0] key Key used to identify a test user
21
+ # @param [String] user_params[1] username Name used to login with user. In email address format.
22
+ # @param [String] user_params[1] security_token Security token of user
19
23
  def initialize(*user_params, description: nil)
20
24
  self.key = user_params[0]
21
25
  self.username = user_params[1]
26
+ self.security_token = ENV["#{key}_token"] || nil
22
27
  self.description = description
23
28
  end
24
29
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module LeapSalesforce
4
4
  # @return [String] Version of leap salesforce
5
- VERSION = '1.0.5'
5
+ VERSION = '1.2.0'
6
6
  end
@@ -8,6 +8,7 @@ Soaspec.log_warnings = false # Log any API warnings
8
8
  Soaspec::SpecLogger.progname = 'Leaps' # Program name shown in logs
9
9
  Soaspec::OAuth2.request_message = false # Don't display message explaining OAuth request
10
10
  Soaspec::OAuth2.retry_limit = 1 # Retrying for OAuth token too many times results in user locked out
11
+ require 'active_support/isolated_execution_state'
11
12
  require 'active_support/core_ext/integer/time' # Creating time objects
12
13
  require 'leap_salesforce/parameters' # Important to load this first
13
14
  require 'leap_salesforce/ext/string'
@@ -18,6 +19,7 @@ require 'factory_bot' # For mass production of data
18
19
  require 'faker' # For fake data
19
20
  require 'leap_salesforce/error'
20
21
  require 'leap_salesforce/loader'
22
+ require 'leap_salesforce/session'
21
23
 
22
24
  # If variable is present within LeapSalesforce set it
23
25
  def load_variables_from(file)
@@ -81,3 +83,5 @@ module LeapSalesforce
81
83
 
82
84
  self.objects_to_verify = SoqlData.descendants if objects_to_verify.empty?
83
85
  end
86
+
87
+ LeapSalesforce.api_user = LeapSalesforce::Users.list.first.username
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leap_salesforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-01-13 00:00:00.000000000 Z
12
+ date: 2022-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -101,14 +101,14 @@ dependencies:
101
101
  requirements:
102
102
  - - '='
103
103
  - !ruby/object:Gem::Version
104
- version: '6.1'
104
+ version: '7'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - '='
110
110
  - !ruby/object:Gem::Version
111
- version: '6.1'
111
+ version: '7'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: colorize
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -333,6 +333,7 @@ files:
333
333
  - lib/leap_salesforce/rake.rb
334
334
  - lib/leap_salesforce/rake/setup.rake
335
335
  - lib/leap_salesforce/rake/sfdx.rake
336
+ - lib/leap_salesforce/session.rb
336
337
  - lib/leap_salesforce/soql_data/common_enum_methods.rb
337
338
  - lib/leap_salesforce/soql_data/data_relationships.rb
338
339
  - lib/leap_salesforce/soql_data/meta_data_handler.rb
@@ -370,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
371
  - !ruby/object:Gem::Version
371
372
  version: '0'
372
373
  requirements: []
373
- rubygems_version: 3.0.6
374
+ rubygems_version: 3.2.3
374
375
  signing_key:
375
376
  specification_version: 4
376
377
  summary: Helps with setting up integrated automated test frameworks against Salesforce.