Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Switch to using rack-bodyparser #36

Merged
merged 4 commits into from
Nov 22, 2017

Conversation

alexjfisher
Copy link
Member

No description provided.

@@ -15,4 +15,8 @@ def verify_signature(payload_body)
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), settings.github_secret, payload_body)
throw(:halt, [500, "Signatures didn't match!\n"]) unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
end

def payload
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. It's only very slightly more convenient than using env['parsed_body'] and there might be a better way. I'm going to see what https://github.com/aars/rack-bodyparser#patch-rackrequest is all about.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Even if it's not that much shorter, it's much clearer naming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I did look at https://github.com/aars/rack-bodyparser#patch-rackrequest, but it didn't really seem much of an improvement. Instead of env['parsed_body'] you could use eg request.payload.

return false unless @data['repository'].key? 'html_url'
return false unless @data['repository']['html_url'] =~ %r{github\.com}
true
@env.key?('HTTP_X_GITHUB_EVENT')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the big win. It's so much nicer now that we have easy access to the headers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much safer too, since that's the public API. Relying on internal implementation details always seems so hacky. (not to mention that it would fail on self-hosted GitHub appliances.)

@@ -6,4 +6,12 @@
expect(last_response).to be_ok
expect(last_response.body).to eq('{"status":"success","message":"running"}')
end

it '/echo returns parsed payload' do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the parser via a route might be easier than testing the parser class directly?

@voxpupuli voxpupuli deleted a comment Nov 21, 2017
@voxpupuli voxpupuli deleted a comment Nov 21, 2017
@@ -12,6 +12,10 @@ def self.registered(puppet_webhook)
puppet_webhook.get '/heartbeat' do
return 200, { status: :success, message: 'running' }.to_json
end

puppet_webhook.post '/echo' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we should have this here. The function that this endpoint is providing can already be found via Ruby development tools, the puppet_webhook log, and the spec tests.

@alexjfisher
Copy link
Member Author

For reference. Here is my idea about how we could update the parser testing. alexjfisher@2600e1c

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.5%) to 40.141% when pulling cb60a69 on alexjfisher:rack_body_parser into e1557d7 on voxpupuli:master.

@voxpupuli voxpupuli deleted a comment Nov 21, 2017
@alexjfisher
Copy link
Member Author

alexjfisher commented Nov 21, 2017

Test coverage is down quite a bit by stubbing detect_vcs. Whatever approach we take, we should probably get it back to where it was before merging anything. I think I want to at least include the attribute accessor changes from alexjfisher@2600e1c#diff-8a56f49e6638cadc28a93357766ba2a7

P.S. Since I opened the PR, github won't let me review it (which kinda sucks). I must also remember to edit the commit message on my first commit. It's still marked WIP.

Copy link
Member

@binford2k binford2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, reducing coverage by removing unhelpful tests is still a net positive. I'm digging this.

@alexjfisher
Copy link
Member Author

@binford2k I was fine with removing the /echo endpoint, but how should we test detect_vcs ?

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.0%) to 40.714% when pulling a41e1a0 on alexjfisher:rack_body_parser into e1557d7 on voxpupuli:master.

@voxpupuli voxpupuli deleted a comment Nov 22, 2017
@alexjfisher
Copy link
Member Author

Added slightly tweaked version of ekohl@5afb937 and rebased.

@voxpupuli voxpupuli deleted a comment Nov 22, 2017
@@ -25,6 +25,10 @@ module Methods
def read_fixture(name)
File.read(File.join(File.expand_path('..', __FILE__), 'fixtures', name))
end

def read_json_fixture(name)
JSON.load(read_fixture(name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess I should have used JSON.parse instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. Just spotted that. Commit amended and repushed.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 45.357% when pulling 46c5683 on alexjfisher:rack_body_parser into e1557d7 on voxpupuli:master.

@alexjfisher
Copy link
Member Author

@bastelfreak Odd the codacy-bot can't delete its own comments.

@voxpupuli voxpupuli deleted a comment Nov 22, 2017
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those codacy comments really adding something or can we disable them? You can always view the details on the website.

This was unreachable since we raise an error if we don't detect one of
the supported VCSs.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 45.52% when pulling 471852f on alexjfisher:rack_body_parser into e1557d7 on voxpupuli:master.

@alexjfisher
Copy link
Member Author

@ekohl Personally, I quite like them. I can see how they'd be useful when we have new contributors.

@voxpupuli voxpupuli deleted a comment Nov 22, 2017
@@ -87,8 +87,6 @@ def deleted?
@data['push']['changes'][0]['closed']
when 'tfs'
@data['resource']['refUpdates'][0]['newObjectId'] == '0000000000000000000000000000000000000000'
else
false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you remove this? I actually like being able to rely on a boolean.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unreachable. We already raise an exception if we can't detect a VCS. I can put it back though.

@alexjfisher
Copy link
Member Author

I think I should set something for 'COVERAGE DECREASE THRESHOLD FOR FAILURE' in coveralls though. We haven't really reduced our coverage, but we have removed code and that's given us a smaller percentage.

@alexjfisher alexjfisher changed the title WIP: Switch to using rack-bodyparser Switch to using rack-bodyparser Nov 22, 2017
@alexjfisher alexjfisher merged commit c14fa35 into voxpupuli:master Nov 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants