poltergeist onConsoleMessage initialization on Capybara - ruby-on-rails-4

I'm using the phantomjs driver via poltergeist on ruby/capybara. One thing I'm trying to setup is the ability of receiving debug messages from javascript into the ruby debug console.
I see that phantomjs has a javascript OnConsoleMessage callback to set up this, but I couldn't find a way to wire this up from ruby. Any ideas?

Ok, it seems that you need to enable the inspector
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {debug: true, :timeout => 90, :inspector => true})
end
Capybara.javascript_driver = :poltergeist
and then place
page.driver.debug
somewhere on the spec, which will bring a link to the inspector dashboard. It doesn't reload by default, so you need to hit reload from time to time to see changes

Related

How to solve Apollo Studio Sanbox Cors?

I can't use apollo Studio. After migration for Graphql playground. When I try to run in localhost and redirect me to apollo studio sanbox https://studio.apollographql.com/sandbox?endpoint=http%3A%2F%2Flocalhost%3A5018%2Fgraphql: Unable to connect to localhost.
Please help to solve this
Add CORS configuration options for the server's CORS behavior.
const server = new ApolloServer({
cors: {
"origin": "https://studio.apollographql.com",
"credentials": true
},
typeDefs,
resolvers,
});
Update
I was able to solve my problem. I had added the helmet middleware to Express and just needed to update the contentSecurityPolicy setting.
export default async (app: express.Application) => {
app.use(config.graphqlPath, express.json());
app.use(cors());
app.use(
helmet({
contentSecurityPolicy:
process.env.NODE_ENV === 'production' ? undefined : false
})
);
};
Not sure if that helps since there were not a lot of details on the environment in the original post, but maybe this can help someone else in the future.
Original Post
I'm having the same issue only with Apollo Sandbox. I just get a page stating that I appear to be offline. I checked the console and there are a number of CORS errors.
I also attempted to switch to the GraphQL Playground as a plugin. It displayed the initial loading screen, but never progressed past that point. I checked the console and also saw similar CORS errors.
I'm using apollo-server-express. I've created Apollo servers in the past and have never run into this while trying to run tools locally.
Apollo now supports an embedded version of the Apollo Sandbox & Apollo Explorer that you can host on your Apollo Server endpoint urls. This will remove the need to whitelist the Apollo Studio endpoint in your CORS configuration to use our Explorer. You can use the Explorer right on your server endpoint.
For local development endpoints, pass embed: true to the ApolloServerPluginLandingPageLocalDefault plugin in your Apollo Server config. See more details here.
For production endpoints, pass a graphRef and embed: true to the ApolloServerPluginLandingPageProductionDefault plugin in your Apollo Server config. See more details here.

rails 4 omniauth developer strategy - error on callback - ActionController::InvalidAuthenticityToken in SessionsController#create

c9 ide, Ubuntu workspace, rails 4.2.10, ruby 2.4.0
When trying to use omniauth gem in developer mode with developer strategy, login link to 'auth/developer' successfully presents form to user. Upon form submission (where route is 'auth/developer/callback') this error is generated:
ActionController::InvalidAuthenticityToken in SessionsController#create
Would like to be able to use developer strategy during the remainder of application development. Documentation doesn't seem to specify anything else needed for the callback when using the developer strategy (in development mode). There does seem to be at least one small discrepancy in the doc, is something missing as well??
All code working properly when using actual providers or during test mode with cucumber.
Here is portion of initializer code (not including keys/secrets) which I started with in config/initializers/omniauth.rb:
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :github, 'redacted,'redacted',
{ :name => "github", :scope => ['read:user','user:email']}
provider :facebook, 'redacted', 'redacted'
end
Gemfile includes:
gem 'omniauth'
gem 'omniauth-github'
gem 'omniauth-facebook'
routes.rb:
match 'auth/:provider/callback', :to => 'sessions#create', :via => [:get, :post]
sessions_controller:
def create
begin
authenticator = Authentication.new(env["omniauth.auth"])
authenticator.disallow(session[:user_id]) if session?
authenticator.deny if authenticator.missing_information?
auth, message = authenticator.register_or_login
session[:user_id] = auth.user.id
etc.
app/controllers/sessions_controller/authentication.rb:
def initialize(omniauth)
# get Omniauth authentication hash
#auth_hash = omniauth
end
def auth_hash
#auth_hash
end
etc.
When successful (using other providers or in test mode), callback should be provided with valid token, path of code can then easily be traced through create method of sessions_controller to the constructor of the Authenticator class, etc.
When in development mode using developer strategy, the body of the sessions create method is never entered at all.
After getting valid token, I should see messages such as:
"Welcome <name> You've signed up via <provider>."
However, since error is raised before that point, only see the following in the server output:
Processing by SessionsController#create as HTML
Parameters: {"name"=>"Example User", "email"=>"example#user.com", "provider"=>"developer"}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
actionpack (4.2.10) lib/action_controller/metal/request_forgery_protection.rb:181:in `handle_unverified_request'
I found this in another section of the Wiki:
Rails session is clobbered after callback on Developer strategy
The developer strategy callback is sent using POST request. Disable forgery protection for given action, otherwise session will be clobbered by rails.
skip_before_action :verify_authenticity_token, only: :create
This definitely works, but I still have a few questions.
Is the before_action defined and handled by omniauth itself, or should I add it to my controllers when NOT in developer mode?
It looks as though this scheme works by just adding that line in developer mode, and deleting it in production, which seems pretty unreliable. Is there a way to enforce it automatically instead?

Loading test pages within a unit test in the firefox-addon-sdk

My add-on involves the user interface, and so to test it I decided to simply have a html page which will load and the tester can follow some instructions on the page.
Here is an example of loading the page:
exports["test interaction"] = function(assert, done) {
require("sdk/tabs").tabs.open({
url: "./tests/test-page.html",
onClose: function(tab) {
assert.pass("Done page test");
done();
});
};
However, after about 16 seconds the tests will always fail with two error messages:
fail:
Timed out (after: START)
and
fail:
Should not be any unexpected tabs open
Furthermore, and more importantly, my addon does not work at all using cfx test, while it works using cfx run on the same test pages.
Is there a way to load some HTML testing pages using cfx test?
Adding tab.close() before done() will fix the "Should not be any unexpected tabs open" error.
I think what you need to do is listen for messages from the tab you opened and then manually close the tab. You can send messages by injecting a content script into the tab, and communicating back. Something like:
page is opened
page runs some tests, and on completion or error, sends data via window.postMessage to the content script
the content script relays these results back to the tab worker
the tab worker closes the tab

Drupal 7 - Getting data from webservice just for presentation

I have a use case where I have to consume the data from the some web service. I don't have to store that data on Drupal database, but I might cache(optional) and present the data on the browser. Drupal is just a interface between the webservice and client browser. I was looking on the modules that can be used to handle the remote activities including "Remote entity", "Feeds". But I think those modules are overkill just for getting data and rendering on the browser and also I think I had to store data on drupal with those modules. Basically I am looking for some module that will just get the data on realtime from webservice and I could use that and present that to browser on same http request.
Otherwise I am ready and set to jot down custom module!! :)
Install webservices module and create the custom module for getting the results for example showing the albums photo...or if you use view in drupal then services view module is good with services module..
You can create menu items in custom module's hook_menu like following
$menu_items['web-service-path'] = array(
'title' => 'web service title',
'type' => MENU_CALLBACK,
'delivery callback' => 'ajax_deliver', // Will make sure that complete drupal bootstrap does not load and only service code runs.
'page callback' => 'web-service-callback-function',
'access callback' => true, // Allow all users
);

reset_session not doing anything

I'm building a rails 4 app with JRuby on Torquebox, and running into a weird issue with the sessions. I'm using the devise gem to handle authentication which works well, except that as per the rails security guidelines, I'm trying to reset the session when a user successfully logs in.
I've created a Warden hook which handles this for me, which looks like this
Warden::Manager.after_set_user :event => [:set_user, :authentication] do |record, warden, options|
if options[:scope] && warden.authenticated?(options[:scope])
request = warden.request
Rails.logger.debug "session - #{request.session}"
# backup = request.session.to_hash
# backup.delete(:session_id)
request.reset_session
# request.session.update(backup)
Rails.logger.debug "session - #{request.session}"
end
end
This method is definitely being called which is great, however the two outputs are both the same, and the session is not being reset at all. I'm using the TorqueBox session store, setup like
# session_store.rb
RtsBackend::Application.config.session_store :torquebox_store, {
key: '_RtsBackend_session'
}
# config.ru
use TorqueBox::Session::ServletStore
And it seems to be working as TorqueBox has inserted data, and session data from devise is working, but I just can't seem to clear it.
I was under the impression that devise did this automatically on login, but if it is then the same issue is occurring and rails isn't clearing it.
Any suggestions?
So after digging around, and speaking with one of the core TorqueBox developers, it turned out to be a bug. In rails 4, they changed the way sessions were reset which didn't involve clearing its contents.
Thanks to #bbrowning with this commit it should now be sorted pending a final test once the fix is pushed :)