Skip to content

Adjust test setup to use OneLogin::RubySaml::Attributes#248

Closed
doconnor-clintel wants to merge 2 commits into
apokalipto:masterfrom
careright:fix-specs
Closed

Adjust test setup to use OneLogin::RubySaml::Attributes#248
doconnor-clintel wants to merge 2 commits into
apokalipto:masterfrom
careright:fix-specs

Conversation

@doconnor-clintel

@doconnor-clintel doconnor-clintel commented Dec 26, 2023

Copy link
Copy Markdown
Contributor

Split from #245

Here I changed the test setup so that we'd get the expected results, rather than relying on global state from the saml gem and changing the test results.

@doconnor-clintel doconnor-clintel changed the title Adjust test setup Adjust test setup to use OneLogin::RubySaml::Attributes Dec 26, 2023

@adamstegman adamstegman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for updating this test! I have one small suggestion to keep it in line with how it is today.


it "correctly maps the resource key, #{resource_key}, to the value of the '#{saml_key}' SAML key" do
saml_attributes[saml_key] = saml_attributes.delete(resource_key)
saml_attributes[saml_key] = saml_attributes.to_h.delete(resource_key)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

After #to_h, this delete won't have mutated the attributes. Since there isn't a great way to delete an attribute after constructing the Attributes object, what if instead we delayed it until after this mutation?

Suggested change
saml_attributes[saml_key] = saml_attributes.to_h.delete(resource_key)
saml_attributes[saml_key] = saml_attributes.delete(resource_key)
let(:instance) { described_class.new(OneLogin::RubySaml::Attributes.new(saml_attributes), attribute_map) }
# ...
let(:saml_attributes) do
  {
    # ...
  }
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Other question, does it need to .delete and reassign at all?

When I look at it, I'm not really sure why we're it was originally doing basically:

x = {'foo' => 'bar' }
x.delete 'foo'
x['foo]' = 'bar'

Okay the OneLogin::RubySaml::Attributes acts kind of like a hash, just without all of the methods and interface; but what was the original test proving with the modification?

(When I did this change, it was basically 'see test failure, do thing fix test failure'; not really understanding why)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's hard to say for sure. I feel like it's testing that the original name isn't being used, instead the configured name is being used. Another way of accomplishing this would be to create a new attributes object each time, instead of mutating the shared object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, oops, missed that was was saml_key vs resource_key

@doconnor-clintel

Copy link
Copy Markdown
Contributor Author

Unfortunately, I've not had the spare capacity to revisit this one and trial the change.
Closing for the moment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants