Skip to content

Conversation

@JackDoan
Copy link
Contributor

@JackDoan JackDoan commented Sep 15, 2025

  • add tests

@JackDoan JackDoan marked this pull request as ready for review September 16, 2025 15:51

const EnduserAuthPoll = "/v1/enduser-auth/poll"

const EnduserAuthPollStatusNotStarted = "NOT_STARTED"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not need a failure state here? Or would the connection simply close in that case?

Copy link
Member

@johnmaguire johnmaguire left a comment

Choose a reason for hiding this comment

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

Naming stuff applies to the test code too, but I tend not to worry too much about that.

@jasikpark jasikpark self-assigned this Sep 25, 2025
client.go Outdated
Errors message.APIErrors
}
if err := json.Unmarshal(respBody, &errors); err != nil {
return nil, fmt.Errorf("dnclient endpoint returned bad status code '%d', body: %s", resp.StatusCode, respBody)
Copy link
Member

Choose a reason for hiding this comment

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

Looking closer, and I think this isn't quite right. This code comes from postDNClient which is used to contact the /v1/dnclient endpoint (hence the "dnclient endpoint" in the error.) This endpoint differs from our primary API:

  • It uses a different authentication method, for dnclient
  • It doesn't use our standard response format (Data vs. Errors)
  • It has a couple envelopes, which are base64-encoded and signed

Take a look at the Enroll call for how we want to handle this - primarily, we attempt to deconstruct the Errors array.

I think that ultimately we want to create a callAPI function, similar to postDNClient, using Enroll as a basis for how to process the message , that is used for enroll, poll, and preauth.

Probably we can remove Errors from the message structs for these calls if we process them in one place like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough. I really would like to land this, so I'm choosing to punt on DRY-ing handling bodies for now if that's cool with you

const EndpointAuthPollStatusNotStarted = "NOT_STARTED"
const EndpointAuthPollStatusWaiting = "WAITING"
const EndpointAuthPollStatusStarted = "OIDC_STARTED"
const EndpointAuthPollStatusSuccess = "SUCCESS"
Copy link
Member

Choose a reason for hiding this comment

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

In the final PR, the states that landed were:

WAITING (user has not initiated OIDC), STARTED (waiting on OIDC to complete) and COMPLETED: https://github.com/DefinedNet/api/blob/4f575743842f915ced7dd86c588375d07c641c22/pkg/data/endpoint_auth.go#L51-L53

This doesn't match the doc, and I apologize. Will update now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should these get pulled into api from dnapi?

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean having api import dnapi and use the constants from it?

I would argue no - it doesn't seem to me that a client library should be responsible for how the server behaves. If this repository changes the constants, and api is importing them, it would immediately create a backwards incompatibility in the api that would be non-obvious to whoever updated the dnapi dependency.

dnapi is a public repo so that we can import it into mobile_nebula, and for this reason, I prefer it to be independent from the api.

s.expectedRequests = s.expectedRequests[1:]
res := expected.dncRequestResponse
w.WriteHeader(res.statusCode)
_, _ = w.Write(res.response(message.RequestWrapper{}))
Copy link
Member

Choose a reason for hiding this comment

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

This does not look correct to me. This is for a /v1/dnclient endpoint message.

Doesn't preauth need to return a pollToken in order for the poll endpoint to behave correctly? I think we should add a test that the handler receives the poll token sent by the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does! The test injects the "desired response" from the server, and confirms the client gets it. There's no "real handler" because PreAuth doesn't take arguments from the client.

Copy link
Member

@johnmaguire johnmaguire left a comment

Choose a reason for hiding this comment

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

LGTM!

@JackDoan JackDoan merged commit b93d4f7 into main Sep 30, 2025
2 checks passed
@JackDoan JackDoan deleted the oidc branch September 30, 2025 17:33
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.

4 participants