Authentication exception in jmongo - ruby

I'm using Jmongo 1.1.5 in a Rails app running under Jruby 1.6.7
I'm attempting to connection to a mongodb instance with authentication enabled.
I don't have any trouble doing this from the mongo CLI tool using db.auth('user', 'pass').
In my Jruby app I connect like this:
client = Mongo::Connection.new
db = client.db('my_database')
db.authenticate('user', 'pass')
I don't have trouble using mongo this way when the server doesn't run with --auth.
The #authenticate call always returns false with valid creds. Digging further,
I found an exception caught and eaten inside the gems/jmongo-1.1.5/lib/jmongo/db.rb:
caught in authenticate: user: cannot convert instance of class
org.jruby.RubyString to
class [C lib/jmongo/db.rb:50:in `authenticate'
(I hacked the gem's db.rb to see the exception)
Has anyone seen something like this?

It turns out to be a jmongo bug fixed in
https://github.com/marclove/jmongo/commit/788244d6b575d49715809e7668e3ad548951e6b6
To work around this issue, wrap password like this:
db.authenticate('user', java.lang.String.new('password').toCharArray)

Related

Bypassing "Insecure Content Blocked" with Selenium Ruby script

I am fairly new with using Selenium in my Ruby script. Basically my script will make a get request to some url and log in. However my script is failing to send the email and log in automatically due to the Google Chrome pop up about insecure content blocked since one of the images on the page is using http and not https.
I was able to run the script successfully months ago however just recently when trying again, it is unable to proceed with logging in so I dont know why it stopped working all of a sudden.
The error that I see in terminal is this. In irb, I can go through each line of code successfully including using Selenium's "send_keys" and "click" to automatically sign in.
[2018-09-26T13:02:55.002527 #14131] INFO -- : [#http://company.com/favicon.ico'. This request has been blocked; the content must be served over HTTPS.">]
web_app.rb:54:in `': Console Errors Found! (Exception)
I tried searching for some solution but have been unsuccessful. There has been some variations of responses to similar problem but not too much luck with getting it to work.
Any feedback on how to fix would be appreciated.
start Chrome manualy and disable the warning - https://www.thewindowsclub.com/disable-insecure-content-warning-chrome
and use the set browser profile, there is my setup:
#BeforeClass
public static void setUpClass() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\pburgr\\Desktop\\chromedriver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(options);
driver.manage().window().maximize();}

How to programatically create Hobby of type `Dyno` from Heroku API (Preferrably with Ruby)?

The following method returns a 422 HTTP status code when I attempt to create a Dyno with the heroku app api:
client = PlatformAPI.connect_oauth(API_KEY)
dyno_interface = PlatformAPI::Dyno.new(client)
begin
dyno_interface.create('my-cool-app', {"command" => " bin/rails server -p
$PORT -e $RAILS_ENV", "size" => "hobby", "type"=> "run"})
rescue => e
resp = e.response
end
It fails with the message: Requested type Hobby is not available. Please use Free.
If it matters, I've tried on different versions of the Ruby client, (version 2.0.0). Also, my app does not currently have a Procfile but I was unsure if this would matter.
TLDR: How can I automatically create Dynos of type Hobby via the Heroku API (preferably in Ruby).
Never did figure out how to change the dyno type from Ruby so instead we ended up calling bash/Heroku CLI from ruby.
Still interested if anyone knows how to do this from Ruby.

unable to connect to back4app using parse4cn1 lib

Good day all, I tried connecting to the back4app back end service using the new parse4cn1 lib .....I supplied the keys required but my app could not connect to the backend for some strange reasons.kept reporting (unable to connect to back end.........codename one revisions some long numbers)
Some help or direction will be appreciated.Thanks all
What keys are you using? You need to pass your App Id and Client Key to parse4cn1. I just ran the regression tests against back4app and I didn't get any connection error. Can you provide more details (e.g. a dump) of the error you're getting?
Where are you putting your Parse.initialize? Just went for some digging on parse4cn1 and it seems that it needs to be inside a "initVars" function, usually created within a state machine as you can see in the example below:
public class StateMachine extends StateMachineBase {
/**
* this method should be used to initialize variables instead of
* the constructor/class scope to avoid race conditions
*/
protected void initVars(Resources res) {
Parse.initialize(API_ENDPOINT, APP_ID, CLIENT_KEY);
}
}
Maybe that can help you on this connection issue. Also check the link below (A very useful guide) for further info:
https://github.com/sidiabale/parse4cn1/wiki/Usage-Examples

Can anyone make grizzly-websockets-chat work under standalone grizzly?

I'm struggling to run grizzly-websockets-chat. I've successfully compiled the sample. HttpServer.createSimpleServer is running and serving a test index.html on localhost:8080. WebSocketEngine.getEngine().register("/chat", chatApplication) executes without complaint. However, localhost:8080/chat returns "Resource identified by path '/chat', does not exist.". This is not under Glassfish - just standalone Grizzly/2.2.19.
Comments in some places suggest that websocket support is off by default - I'm unable to determine how to turn it on outside of Glassfish. I have only the test index.html in docroot.. is anything else required?
I'm not running anything special on the client side - no js, nothing. I've not seen any such thing in the sample. Surprisingly, I've not found a good doc or running example. Maybe is a user problem? ;/
Looks like websocket code may be being invoked:
$ java -jar ./tyrus-client-cli-1.1.jar ws://localhost:8080/chat
# Connecting to ws://localhost:8080/chat...
# Failed to connect to ws://localhost:8080/chat due to Handshake error
Any help much appreciated!
Change your request URI to ws://localhost:8080/grizzly-websockets-chat/chat.
The ChatApplication has the following defined for isApplicationRequest():
#Override
public boolean isApplicationRequest(HttpRequestPacket request) {
return "/grizzly-websockets-chat/chat".equals(request.getRequestURI());
}

Timeout Problem with Ruby Fog when bootstrapping AWS servers

I've been trying for a little while now to provision a small instance on AWS with the fog library. I've been somewhat successful (in that an instance does spool up when I run this code), but I keep getting timeout errors during the SSH portion, and when I dug deeper I found that they're consistently "AuthentitcationFailed" problems.
The failing code is as follows:
require 'rubygems'
require "fog"
connection = Fog::Compute.new({
provider: "AWS",
aws_secret_access_key: SECRET_KEY,
aws_access_key_id: ACCESS_KEY
})
server = connection.servers.bootstrap({
private_key_path: "~/.ssh/id_rsa",
public_key_path: "~/.ssh/id_rsa.pub",
username: "ubuntu"
})
Much reading has told me that sometimes this is just because the instance takes too long to spool up, but this is very consistent (it happens every time I try it). Does anyone see what I'm doing wrong?
I had the same problem some days ago and actually found the problem for my case and submitted it to the Fog issue tracker.
A colleague of mine was using connection.bootstrap() with the same AWS credentials but different SSH keys. So the "fog_default" public key had already been registered and the attempt to log in with my key pair failed.
If you're experiencing similar problems, check with connection.key_pairs.get('fog_default') if fog_default was registered before.
If this is actually the case, you have three options to get around this problem:
Delete the fog_default by running: connection.key_pairs.get('fog_default').destroy and register your new public key via bootstrap()
Manually register your custom key under a custom name
Set Fog.credential to a custom name so bootstrap() uses this name instead of "default" to register your public key
Solution two looks like this:
Fog.credentials = Fog.credentials.merge({
:private_key_path => "./keys/my_custom_key",
:public_key_path => "./keys/my_custom_key.pub"
})
if connection.key_pairs.get('my_custom_key').nil?
public_key = IO.read('./keys/my_custom_key.pub')
connection.import_key_pair('my_custom_key', public_key)
end
server = connection.servers.bootstrap(
:key_name => 'my_custom_key',
...
)
Solution three, which I prefer because the only change I need to make is to set Fog.credential, looks like this:
Fog.credential = :my_custom_key
connection.servers.bootstrap(
:private_key_path => './keys/my_custom_key',
:public_key_path => './keys/my_custom_key.pub',
...
)
I'd recommend a few things to diagnose the problem (if you're still having it)
Check your security groups to make sure port 22 is open to your IP / the world (0.0.0.0/0)
Try connecting manually using SSH
If you still see issues, try
ssh -v -v <normal options>
This will give you more information on what is happening when trying to connect to the instance.

Resources