stop behat on 500 errors with mink

I had some issues diagnosing 500 errors that were happening with Mink. The main issue being that a page would 500, but then the test would proceed and fail a later step. Unfortunately the HTML/screenshot that was captured does not capture the error, but instead captures the assertion which doesn’t help debug.

It’s possible to react after a step and check if the last Mink request was a 500 or not. This way, we fail on the 500, and not on the subsequent assertions.

<?php
  /**
   * @AfterStep
   */
  public function afterStep(Behat\Behat\Hook\Scope\AfterStepScope $scope) {
    // Fail if we got a 500.
    try {
      $this->minkContext->assertSession();
      $this->minkContext->assertNotHttpResponse(500);
    }
    catch (Behat\Mink\Exception\DriverException $e) {
      // Page is not loaded.
    }

  }

 

PHP commandline OAuth authorization for JIRA

I needed to get a user’s OAuth credentials from the commandline, for some commandline tools to work (Drush).

You will need OAuth installed from PECL for this, and have an OAuth link set up in JIRA (or whatever OAuth provider you are using).

// Set up the OAuth client.
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_RSASHA1, OAUTH_AUTH_TYPE_URI);

// cert.pem is the certificate you generated for the OAuth link.
$oauth->setRSACertificate(file_get_contents("cert.pem"));

// Get a request token so we can tell the user to visit a page.
$tokens = $oauth->getRequestToken(OAUTH_REQUEST_URL, 'oob', 'POST');
$oauth_token = $tokens['oauth_token'];
$oauth_token_secret = $tokens['oauth_token_secret'];
$oauth->setToken($oauth_token, $oauth_token_secret);
print "Go to: " . OAUTH_AUTHORIZE_URL . "?oauth_token=$oauth_token\n";

// Get the authorization code from the user.
$code = readline('Enter the authorization code');
$access_token = $oauth->getAccessToken(OAUTH_ACCESS_URL, NULL, $code, 'POST');
$oauth->setToken($access_token['oauth_token'], $oauth_token_secret);
$tokens['access_token'] = $access_token['oauth_token'];

// From now on you would just need the access token, and the token secret.
$oauth->setToken($tokens['access_token'], $tokens['oauth_token_secret']);
$oauth->fetch("https://protected-url.com/resource");
$content = $oauth->getLastResponse();

 

launch a jenkins slave via drush

If you already have Drush aliases set up for your live machines, deploy those aliases to your CI server, and use them to launch your nodes (instead of copying the SSH info).

Create a new “Dumb slave” but instead of “SSH slave”, select “Launch slave via execution”

This is the command to use:

/usr/local/bin/drush @abclive ssh 'wget https://your-jenkins-server.example.com/jnlpJars/slave.jar -O /tmp/slave.jar && exec java -jar /tmp/slave.jar'

Jenkins will run the command which sets up the remoting capabiliity.

Liberation – Day 67

9 weeks post-op…they’re off!!!

I thought I was going in to get the surgical lugs and metal wires removed but…

Dr. decided everything was close enough, and took it all off!

I’ve got Invisalign (Vivera?) retainers now, barely visible and sometimes I forget I’m wearing them. Dr. was able to remove the braces now because the retainers also do minor corrective work.

It’s been a long journey. It’s completely worth it. My bite is awesome. Things like very crunchy fruits, peanuts, etc. are still off limits. I still have issues with jaw strength but it’s slowly getting better.

June 2013 – braces
August 2013 – no more wisdom teeth
October 2014 – lefort 1
November 2014 – no more bands
December 29th, 2014 – no more braces!

I could have done the surgery as early as June, but I was lazy…

So that’s that! Checkups and cosmetic work next.

Day 61

It’s been 2 months since the surgery, and so far it’s been much more manageable than the first month. I saw my orthodontist last month and my jaw needed to open more before getting any other work done.

There really isn’t anything else to report on. I’ve been on my own and haven’t been back to the orthodontist or my surgeon. Life is mostly back to normal and I can eat almost as many things as I could eat while in braces, except hard or crunchy things like fruits.

One thing that stood out for me this month was that I could eat a burrito without having to shove the entire thing in my mouth. I was able to use my front teeth to tear it apart (gently) for the first time in a very long time.

There’s still a lot of numbness in my upper gums but that’s to be expected. It doesn’t really affect any day to day activities. A month ago I could open my mouth about 1 finger wide, now it’s more than 3, which is a good sign that things are still healing.

I’m due to the orthodontist on the 29th so we’ll see what happens then.