hydra-client-go icon indicating copy to clipboard operation
hydra-client-go copied to clipboard

Incorrect Logic in OAuth2Client.HasMetadata()

Open chrutzer opened this issue 1 year ago • 0 comments

Preflight checklist

Ory Network Project

No response

Describe the bug

The HasMetadata() function in OAuth2Client isn't working right. It should tell us with a true if there's stuff in the Metadata field. But, it's doing the opposite. It's supposed to say true when there's something in Metadata, not when it's empty.

Reproducing the bug

  1. Start by creating an OAuth2Client instance with some data in the Metadata field. For example:
client := OAuth2Client{
    Metadata: &Metadata{ /* Assume this is correctly initialized with data */ },
}
  1. Next, call the HasMetadata() method on this instance to check if the metadata is considered set:
hasMeta := client.HasMetadata()
  1. Check the result of hasMeta. Despite having filled the Metadata field in step 1, you'll surprisingly find hasMeta is false.
fmt.Println("Does client have metadata:", hasMeta) // Expected: true, Actual: false

Relevant log output

No response

Relevant configuration

No response

Version

v2.2.0

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Kubernetes

Additional Context

Obvious bug in the current implementation:

func (o *OAuth2Client) HasMetadata() bool {
	if o != nil && IsNil(o.Metadata) {
		return true
	}

	return false
}

chrutzer avatar Mar 01 '24 18:03 chrutzer