Mail Chimp & Rails Gibbon Gem - hostname does not match the server certificate - ruby-on-rails-3

Just integrated the Gibbon, gem and I am getting a hostname does not match the server certificate error thrown back when trying to subscribe a new user?
def subscribe_to_mailchimp testing=false
return true if (Rails.env.test? && !testing)
list_id = ENV['My-list-id']
response = Rails.configuration.mailchimp.lists.subscribe({
id: list_id,
email: {email: email},
double_optin: false,
})
response
end

Slight change in the way that this works from the last time i looked seems to have fixed the issue.
Firstly
def subscribe_to_mailchimp testing=false
return true if (Rails.env.test? && !testing)
list_id = 'My-list-id'
response = Rails.configuration.mailchimp.lists.subscribe({
id: list_id,
email: {email: email},
double_optin: false,
})
response
end
Secondly
in config/initializers/mailchimp.rb
if Rails.env.test?
Gibbon::Export.api_key = "fake"
Gibbon::Export.throws_exceptions = false
end
Gibbon::API.api_key = "YOUR_API_KEY"
Gibbon::API.timeout = 15
Gibbon::API.throws_exceptions = false
Rails.configuration.mailchimp = Gibbon::API.new
Finally in application.rb
require 'openssl'
The Require openssl was what was generating the hostname does not match the server error as the call in the Gibbon app uses https
And if your interested in users.rb
def subscribe_to_mailchimp testing=false
return true if (Rails.env.test? && !testing)
list_id = "YOUR_LIST_ID"
response = Rails.configuration.mailchimp.lists.subscribe({
id: list_id,
email: {email: email},
double_optin: false,
})
response
end

Related

Dependabot nuget pull request

I have an API where I want nuget packages to update with my own feed, but when I get to this UpdateCheckers setting it shows me update_not_possible.
The project is hosted on azure just like the nugets feed
When the build is executed, it only executes and does not create pull request, the se only in Found # {dep.name} # # {dep.version} ...
require "dependabot/file_fetchers"
require "dependabot/file_parsers"
require "dependabot/update_checkers"
require "dependabot/file_updaters"
require "dependabot/pull_request_creator"
require "dependabot/pull_request_updater"
require "dependabot/omnibus"
package_manager = "nuget"
repo_name = "/myproject/_git/WebApi.Dummy"
directory = "src/WebApi.Dummy"
branch= "Dependabot"
azure_hostname = "https://dev.azure.com/myorganization/myproject" || "dev.azure.com"
credentials = [{
"type" => "git_source",
"host" => azure_hostname,
"username" => "x-access-token",
"password" => "my_personal_token"
},{
"type" => "nuget_feed",
"url" => "https://dev.azure.com/myorganization/myproject/_packaging/myfeedNuget/nuget/v3/index.json",
"token" => ":my_personal_token"
}
]
source = Dependabot::Source.new(
provider: "azure",
hostname: azure_hostname,
api_endpoint: "http://#{azure_hostname}/",
repo: repo_name,
directory: directory,
branch: branch
)
puts "Fetching #{package_manager} dependency files for #{repo_name}"
fetcher = Dependabot::FileFetchers.for_package_manager(package_manager).new(
source: source,
credentials: credentials,
)
files = fetcher.files
commit = fetcher.commit
parser = Dependabot::FileParsers.for_package_manager(package_manager).new(
dependency_files: files,
source: source,
credentials: credentials,
)
dependencies = parser.parse
dependencies.select(&:top_level?).each do |dep|
puts "Found #{dep.name} # #{dep.version}..."
checker = Dependabot::UpdateCheckers.for_package_manager(package_manager).new(
dependency: dep,
dependency_files: files,
credentials: credentials,
)
if checker.up_to_date?
puts " already using latest version"
next
end
requirements_to_unlock =
if !checker.requirements_unlocked_or_can_be?
if checker.can_update?(requirements_to_unlock: :none) then :none
else :update_not_possible
end
elsif checker.can_update?(requirements_to_unlock: :own) then :own
elsif checker.can_update?(requirements_to_unlock: :all) then :all
else :update_not_possible
end
next if requirements_to_unlock == :update_not_possible
updated_deps = checker.updated_dependencies(
requirements_to_unlock: requirements_to_unlock
)
puts " considering upgrade to #{checker.latest_version}"
updater = Dependabot::FileUpdaters.for_package_manager(package_manager).new(
dependencies: updated_deps,
dependency_files: files,
credentials: credentials,
)
updated_files = updater.updated_dependency_files
pr_creator = Dependabot::PullRequestCreator.new(
source: source,
base_commit: commit,
dependencies: updated_deps,
files: updated_files,
credentials: credentials,
label_language: true,
author_details: {
email: "dependabot#bccr.fi.cr",
name: "dependabot"
},
)
pull_request = pr_creator.create
if pull_request&.status == 201
content = JSON[pull_request.body]
puts " PR ##{content["pullRequestId"]} submitted"
ENV['PR_ID']="##{content["pullRequestId"]}"
else
puts " PR already exists or an error has occurred"
end
next unless pull_request
end
puts "Done"

Chef InSpec check an http request is failing [successfully]

I am writing some infrastructure testing in Chef InSpec & am not sure how to go about testing that a url is not accessible publicly. I have the following code snippet which I am currently using
environments = {
:ops => "ops",
}
control "verify-not-accessible-publicly" do
impact 1.0
title "verify we are not publicly accessible"
environments.each do |_, env|
uri = "http://#{env}.internal.example.com"
begin
result = http(uri, ssl_verify: true, open_timeout: 2, read_timeout: 5, max_redirects: 0)
rescue => e
unless e.class == Faraday::ConnectionFailed
raise e
end
end
end
end
This isn't working quite like I expect. I don't think the http(uri,...) block is actually executed until it is passed into a describe function.
Thanks
you should use http resource with a describe block and matchers
describe http('url', auth: {user: 'user', pass: 'test'}, params: {params}, method: 'method', headers: {headers}, data: data, open_timeout: 60, read_timeout: 60, ssl_verify: true, max_redirects: 3) do
its('status') { should eq number }
its('body') { should eq 'body' }
its('headers.name') { should eq 'header' }
end

OTRS with LDAP authentication not working

I'm running OTRS 5s on my server and need to configure LDAP authentization in it.
currently i have this code:
$Self->{'AuthModule'} = 'Kernel::System::Auth::LDAP';
$Self->{'AuthModule::LDAP::Host'} = '127.0.0.1';
$Self->{'AuthModule::LDAP::BaseDN'} = 'dc=domain,dc=com';
$Self->{'AuthModule::LDAP::UID'} = 'uid';
$Self->{'AuthModule::LDAP::SearchUserDN'} = 'cn=tester,cn=adminuser,ou=users,dc=domain,dc=com';
$Self->{'AuthModule::LDAP::SearchUserPw'} = 'tester';
last two lines should be ok but I'm getting this error on site
Panic, user authenticated but no user data can be found in OTRS DB!! Perhaps the user is invalid.
I also tried version which I found here and on other sites, but thats not working at all with following code:
$Self->{'AuthModule'} = 'Kernel::System::Auth::LDAP';
$Self->{'AuthModule::LDAP::Host'} = '127.0.0.1';
$Self->{'AuthModule::LDAP::BaseDN'} = 'dc=domain,dc=com';
$Self->{'AuthModule::LDAP::UID'} = 'sAMAccountName';
$Self->{'AuthModule::LDAP::GroupDN'} = 'cn=adminuser,ou=users,dc=domain,dc=com';
$Self->{'AuthModule::LDAP::AccessAttr'} = 'member';
$Self->{'AuthModule::LDAP::UserAttr'} = 'DN';
$Self->{'AuthModule::LDAP::SearchUserDN'} = 'cn=tester,cn=adminuser,ou=users,dc=domain,dc=com';
$Self->{'AuthModule::LDAP::SearchUserPw'} = 'tester';
but it results in wrong password or username and apache error.log calling
ERROR: OTRS-CGI-45 Perl: 5.20.2 OS: linux Time: Mon Dec 5 18:19:41 2016
Message: No UserID found for 'tester'!
both codes have
$Self->{'AuthModule::LDAP::Params'} = {
port => 389,
timeout => 120,
async => 0,
version => 3,
};
Appreciate any help, thanks.
User (agents) need to exists in the database before you can use LDAP authentication for them. Add them manually or configure the AuthSyncModule module.
Use the below parameters after the $Self->{'AuthModule::LDAP::Params'} section:
$Self->{'AuthSyncModule::LDAP::UserSyncMap'} = {
UserFirstname => 'givenName',
UserLastname => 'sn',
UserEmail => 'mail',
};

RestClient::SSLCertificateNotVerified: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I tried to put verify_ssl=>false to the request, but it doesn't work.
Below is my code:
def login_request (username, password)
request_body_map = {:userName => username, :password => password}
request_header = {:content_type => 'application/json', :accept => 'application/json'}
begin
res = RestClient.post endpoint, request_body_map.to_json, {:header => request_header, :verify_ssl => false}
response_data = JSON.parse(res.body)
rescue Exception => e raise e
end
end
please use RestClient::Request.execute(method: :get, url: url, headers: headers, verify_ssl: false)
verify_ssl is not accepted in RestCient.method
Try this:
def login_request (username, password)
request = {'userName': username, 'password': password}.to_json
url = "#{$url_host}#{$login_api}"
begin
res = RestClient.post(
url,
request,
:content_type => :json, :accept => :json,
:verify_ssl => false)
response_data = JSON.parse(res.body)
$user_token = response_data['token']
$userId = response_data['user']['userId']
p response_data['user']['email']
rescue Exception => e
end
end
You can put the authentication details with :varify_ssl.
We're facing the same exact error (B: certificate verify failed) and it's driving me nuts. This started showing up for our developers around the 10th of Oct, 2015.
In authorize.net developer forums there are many threads with the same issue, two of which are recent (first thread) (second thread) and both went dead with no resolution, these two threads started around the same time we started facing this issue, so my guess is that it has to do with authorize.net bad/new certificate with missing certificate chain.
This exact issue appeared before around 2012 and 2014 (check their developer forum), Authorize.net admitted it was a bad change they made to their certificates and then later fixed the issue, but this time it appears to be an ongoing since mid October.
PS: I tried installing every root/chain certificate on our server but this issue persists.

omniauth google_oauth2 the profile image is not present in the authhash

This is written in omniauth.rb an initializer.
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2,ID,SECRET,
{
:approval_prompt => '',
:scope => 'http://gdata.youtube.com,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
}
The returned auth hash does not have IMAGE element in the "info", why?????????
Replaced original info with x in the below HASH
*********************
--- !ruby/hash:OmniAuth::AuthHash
provider: google_oauth2
uid: 'xxxxxxxxxxxxxxxxxxxx'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: xxxx xxx
email: xxxxxxxxxx
first_name: xxxxxx
last_name: xxxxxxx
credentials: !ruby/hash:Hashie::Mash
token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
expires_at: 1365434778
expires: true
extra: !ruby/hash:Hashie::Mash
raw_info: !ruby/hash:Hashie::Mash
id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
email: xxxxxxxxxx.xxx#gmail.com
verified_email: true
name: xxxx xxxx
given_name: xxx
family_name: xxx
link: https://plus.google.com/xxxxxxxxxxx
gender: male
locale: en
*********************
I want the profile image, what am I doing wrong?
Also tried,
{:scope => 'userinfo.email,userinfo.profile'}
Not working!!
Not sure what that scope is doing, but I've just solved getting google info for myself.
Is that information the actual params sent to rails, or is it the saved user hash?
If it's not the actual params you get on login, you can use:
# sessions_controller.rb
raise env["omniauth.auth"].to_yaml
That'll show you everything that google is sending you.
If it's the user and If you've followed Railscasts like I was doing, then check that you've created a field to save the pics and that you've set the field to save the info from the hash. I did this:
# sessions_controller.rb
def create
user = User.from_omniauth(env["omniauth.auth"])
user.image = env["omniauth.auth"]['info']['image']
user.save
session[:user_id] = user.id
redirect_to root_url, :notice => "Signed in!"
end
If that's not what you're needing, can you be more specific?