Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / 1ST README
Last active December 11, 2015 21:39 — forked from rsierra/1ST README.md
Rails 2.3.5 version of the Rails 2.1.1 patch by @rsierra
Rails 2.3.5 patch for CVE-2013-0333 vulnerability:
If you can't upgrade your Rails installation you can get the OkJson parser and include it in your project. How?
- Add cve_2013_0333_patch.rb in '/config/initializers' directory.
- Add okjson.rb in '/lib/active_support/json/backends' directory.
To test the parser, try to decode with a bad formatted json:
(I don't know if it's the best test, but you check if you are using the json parser in the rails 2.3 official patch)
@brenes
brenes / commit
Created February 11, 2013 16:19
Todo.txt addon to commit the added files on a git repo. It searches for a ticket number in the issue line (#TICKET_NUMBER) and opens the default editor with a commit message preloaded with the ticket number
#!/usr/bin/env bash
action=$1
shift
function usage(){
echo " Commits changes for the mentioned issue"
echo " commit ITEM#"
echo " Searches for an issue number in the todo line and opens the default editor with the issue number just to write your commit"
echo ""
@brenes
brenes / Readme.md
Last active June 7, 2017 04:23
Rails <= 2.3 patch for CVE-2013-1854, CVE-2013-1855, CVE-2013-1856 and CVE-2013-1857 vulnerabilities

Rails <= 2.3 patch for CVE-2013-1854, CVE-2013-1855, CVE-2013-1856 and CVE-2013-1857 vulnerabilities

Extracted from official patchs.

  • Add files in '/config/initializers' directory.

Notes

  • CVE-2013-1854 patch had some compatibility issues with has_many_polymorphs as it overwrites the create_reflection method to include the has_many_polymorphs relation. It was solved by including the HMP code into our patch as it should only be executed when a HMP relation is declared.
@brenes
brenes / model_with_attributes.rb
Last active December 15, 2015 11:29
Common shared examples for rspec
shared_examples_for "model with attributes" do |model_name|
context "validations" do
context "with valid values" do
let(:attributes) { attributes_for model_name }
let(:model_object) { build model_name, attributes }
subject { model_object }
@brenes
brenes / spec_helper.rb
Created May 8, 2013 08:45
VCR basic config
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr/'
c.hook_into :webmock # or :fakeweb
c.allow_http_connections_when_no_cassette = true
c.configure_rspec_metadata!
c.default_cassette_options = { :record => :new_episodes, :erb => true, :match_requests_on => [:path] }
c.ignore_request do |request|
uri = URI(request.uri)
uri.host == '127.0.0.1'
@brenes
brenes / admin_controller_decorator.rb
Last active December 19, 2015 07:09
Refinery Admin extension solving Globalize + Crudify issues
# Extension to Refinery Admin controller to avoid 2 problems:
#
# 1) Edit locale propagates through requests as Thread.current[:globalize_locale] is never reset to nil
# 2) Crudify's find filter is pepended before de globalize filter. This way, if you're editing in a non-default locale and the update url comes with a slug in that locale it won't be found (in fact, it does work in some circunstances)
::Refinery::AdminController.class_eval do
# We should reset globalize so we don't propagate Globalize locale between requests
def reset_globalize
Thread.current[:globalize_locale] = nil
@brenes
brenes / gist:6000406
Created July 15, 2013 14:32
Funcion JS para loguear errores de Parsley
$('form').parsley( {
listeners: {
onFieldError: function ( elem, constraints, ParsleyField ) {
if (javascript_env == 'production') {
return;
}
_log("Errores: ")
_log(elem.attr("name") + ": " + elem.val());
for(constraint_id in constraints) {
@brenes
brenes / _header.html.erb
Last active December 22, 2015 22:09
helper method to obtain a fragment cache key depending on the currently selected page on the refinery menu
.......
.......
<% cache menu_cache_key, expire_in: 1.day do %>
<%= render(:partial => "/refinery/menu", :locals => {
:css => 'submenu'
}) %>
<% end %>
.......
.......
@brenes
brenes / responsive_describe.rb
Created December 27, 2013 10:38
Responsive Describe module for running request specs under different resolutions with poltergeist
# This module allows you to run your request specs in a responsive mode quite easily
#
# Requirement: It requries Poltergeist, but could work with any capybara driver with a resize method
#
# Instructions:
#
# 0. Setup Poltergeist and register the driver
# 1. Drop this module in your spec/support folder
# 2. Include this module before your describe
# 3. Use a responsive: true param in describe to enable responsive requests. We will need a js:true to enable poltergeist
@brenes
brenes / test
Created May 27, 2014 09:45
Plugin generator for nested namespaces
testing