how to ignore *.php requests using Apache

I recently deployed a beta version of one of my projects.

A few days went by and then I started getting 404 email notifications to my inbox. It seems that someone was trying to exploit known PHP issues (eg. phpMyAdmin issues, as seen in the picture below)

Exception emails due to exploit attempts

Here is how I solved this issue:

  1. Make sure you have mod_rewrite enabled for your Apache
  2. Write a rule in your VirtualHost that looks like this:
1
2
3
4
5
6
<VirtualHost *:80>
  ServerName example.com
  DocumentRoot /path/to/example.com/current/public
  RewriteEngine On
  RewriteRule    ^.*.php$  404.html  [R]
</VirtualHost>

This will redirect any *.php requests to your 404.html and save resources in your server.

Posted in Ruby programming, open source, web programming | Tagged , , , | Leave a comment

getting started with acts_as_state_machine

This is a note to self. Remember to define all states for an object before you start referencing it.

If not, you will get an error like this:
“You have a nil object when you didn’t expect it! The error occurred while evaluating nil.entering”

This is the solution:

1
2
3
4
5
6
7
8
9
10
11
class Squad < ActiveRecord::Base  
  acts_as_state_machine :initial => :in_progress
 
  event :complete do
    transitions :from => :in_progress, :to => :completed,  
                      :guard => Proc.new {|s| !s.completed_at.blank? }
   end

    state :in_progress # This is the line I had forgotten to write

    state :completed,  :enter => :do_complete

Have fun with acts_as_state_machine!

And keep in mind that acts_as_state_machine is not concurrent. Read more here.

Posted in Ruby programming, programming, software engineering | Tagged , , , , , | Leave a comment

how to stub methods in cucumber

Most of the Cucumber tests that I’ve written don’t need stubbing. But the other day I was trying to test a particular feature which integrated with an external service.

Then, stubbing a call to the external service seemed like the best way to go. Fortunately, since Cucumber 0.8.4, mocking and stubbing is now possible without hacks. See: Mocking and Stubbing with Cucumber.

Here is the gist.

Add this line to your env.rb

1
require 'spec/stubs/cucumber'

Start stubbing methods in your steps.rb files

For example:

1
ExternalService.should_receive(:send).and_return(my_response)
1
User.should_receive(:customer_add_success?).and_return(true)

Next thing I’d like to do is use stubbing to test features in the feature. For example: Test a feature involving recurring events around daylight time savings time.

Posted in Uncategorized | Leave a comment