Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes pry-byebug functionality when running credential_collection_spec.rb #19109

Merged

Conversation

cgranleese-r7
Copy link
Contributor

This PR fixes an issue where trying to debug tests that were opening files

allow(File).to receive(:open).with(filename,/^r/).and_return stub_file

Before

When attempting to debug the tests file were being interpreted as random files. Whereas now it will honour the values set by the tests when debugging:

Error: #<File (class)> received :open with unexpected arguments
  expected: ("user_file", /^r/)
       got: ("/Users/cgranleese/.inputrc")
Diff:
@@ -1 +1 @@
-["user_file", /^r/]
+["/Users/cgranleese/.inputrc"]

After

Now the tests will allow debugging as expected:

Run options:
  include {:focus=>true, :locations=>{"./spec/lib/metasploit/framework/credential_collection_spec.rb"=>[128]}}
  exclude {:acceptance=>true}

Randomized with seed 33905
Metasploit::Framework::CredentialCollection
From: /Users/cgranleese/code/metasploit-framework/lib/metasploit/framework/credential_collection.rb:248 Metasploit::Framework::CredentialCollection#each_unfiltered_password_first:

    243:     #   username2:password2
    244:     #   username3:password2
    245:     # ...
    246:     def each_unfiltered_password_first
    247:       require 'pry-byebug'; binding.pry
 => 248:       if user_file.present?
    249:         user_fd = File.open(user_file, 'r:binary')
    250:       end
    251:
    252:       prepended_creds.each { |c| yield c }
    253:

[1] pry(#<Metasploit::Framework::CredentialCollection>)>

Verification

Example of where a pry could be added to test these changes:

  • Attempt to run the tests will debugging
  • Verify the tests return the error above and doesn't hit the pry
  • Checkout this branch and confirm the pry can now be hit

@cgranleese-r7 cgranleese-r7 added the rn-fix release notes fix label Apr 18, 2024
@cgranleese-r7 cgranleese-r7 changed the title Fixes pry-byebug functional when running credential_collection_spec.rb Fixes pry-byebug functionality when running credential_collection_spec.rb Apr 18, 2024
@cgranleese-r7 cgranleese-r7 force-pushed the fixes-pry-byebug-when-debugging-tests branch from eb7a420 to 2b4fe40 Compare April 18, 2024 13:29
@cgranleese-r7 cgranleese-r7 force-pushed the fixes-pry-byebug-when-debugging-tests branch from 2b4fe40 to 4186d00 Compare April 18, 2024 13:30
@adfoster-r7 adfoster-r7 merged commit ba18e63 into rapid7:master Apr 18, 2024
34 checks passed
@adfoster-r7 adfoster-r7 added rn-no-release-notes no release notes and removed rn-fix release notes fix labels Apr 18, 2024
@cgranleese-r7 cgranleese-r7 deleted the fixes-pry-byebug-when-debugging-tests branch April 19, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-no-release-notes no release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants