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

How can we match requests without basic auth details in VCR #484

Closed
loganathan-s opened this Issue Apr 9, 2015 · 6 comments

Comments

Projects
None yet
4 participants
@loganathan-s

loganathan-s commented Apr 9, 2015

I am using VCR to record the external apis in Rspec, and I would like to match the requests irrespective of the basic authentication credentials, since basic authentication is dynamic in my case.

Given below the sample recorded cassette with basic auth details

https://apiuser:X9byy%5D2tluVLqi@test.com/roles.json

@krainboltgreene

This comment has been minimized.

Show comment
Hide comment
@krainboltgreene

krainboltgreene Apr 9, 2015

Member

Ideologically you can't, because literally those aren't the same request. It'd be like saying "How do I make sure these humans are the same, regardless of their face."

What you can technically do is change how "equality" works. I suggest creating a new object, maybe call it SimplisticRequestMatcher, it knows about N requests:

class SimplisticRequestMatcher
  def initialize(*requests)
    @requests = requests
  end

  def matches?
    @requests.all? do |request|
      # Your condition here
    end
  end
end
Member

krainboltgreene commented Apr 9, 2015

Ideologically you can't, because literally those aren't the same request. It'd be like saying "How do I make sure these humans are the same, regardless of their face."

What you can technically do is change how "equality" works. I suggest creating a new object, maybe call it SimplisticRequestMatcher, it knows about N requests:

class SimplisticRequestMatcher
  def initialize(*requests)
    @requests = requests
  end

  def matches?
    @requests.all? do |request|
      # Your condition here
    end
  end
end
@myronmarston

This comment has been minimized.

Show comment
Hide comment
@myronmarston
Member

myronmarston commented Apr 9, 2015

@mcfiredrill

This comment has been minimized.

Show comment
Hide comment
@mcfiredrill

mcfiredrill Jun 15, 2015

Collaborator

define_cassette_placeholder is probably the easiest way.
https://www.relishapp.com/vcr/vcr/v/2-0-0/docs/configuration/filter-sensitive-data

If you store your basic auth in the environment you could use it like this:

config.define_cassette_placeholder("<BASIC_AUTH>") do
  ENV['BASIC_AUTH']
end
Collaborator

mcfiredrill commented Jun 15, 2015

define_cassette_placeholder is probably the easiest way.
https://www.relishapp.com/vcr/vcr/v/2-0-0/docs/configuration/filter-sensitive-data

If you store your basic auth in the environment you could use it like this:

config.define_cassette_placeholder("<BASIC_AUTH>") do
  ENV['BASIC_AUTH']
end
@myronmarston

This comment has been minimized.

Show comment
Hide comment
@myronmarston

myronmarston Nov 6, 2015

Member

Sorry, @krainboltgreene, I don't have the time to work on this. I unassigned myself in the hope that someone else would pick this up.

Member

myronmarston commented Nov 6, 2015

Sorry, @krainboltgreene, I don't have the time to work on this. I unassigned myself in the hope that someone else would pick this up.

@krainboltgreene

This comment has been minimized.

Show comment
Hide comment
@krainboltgreene

krainboltgreene Nov 6, 2015

Member

@myronmarston It's already closed, I was giving you credit.

Member

krainboltgreene commented Nov 6, 2015

@myronmarston It's already closed, I was giving you credit.

@myronmarston

This comment has been minimized.

Show comment
Hide comment
@myronmarston

myronmarston Nov 6, 2015

Member

@myronmarston It's already closed, I was giving you credit.

Ah. I've never seen "assigned" used that way before.

Member

myronmarston commented Nov 6, 2015

@myronmarston It's already closed, I was giving you credit.

Ah. I've never seen "assigned" used that way before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment