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

Allow initiating client without authentication #75

Merged
merged 3 commits into from
Aug 6, 2020
Merged

Allow initiating client without authentication #75

merged 3 commits into from
Aug 6, 2020

Conversation

violine1101
Copy link
Contributor

While switching over from jira-connector to jira.js, I ran into an issue with setting up the client; in particular, it would crash every time I tried to initiate a client without any authentication.

Exception has occurred: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Authorization"
  at ClientRequest.setHeader (_http_outgoing.js:529:3)
    at new ClientRequest (_http_client.js:241:14)
    at Object.request (https.js:314:10)
    at RedirectableRequest._performRequest (.../node_modules/follow-redirects/index.js:169:24)
    at new RedirectableRequest (.../node_modules/follow-redirects/index.js:66:8)
    at Object.wrappedProtocol.request (.../node_modules/follow-redirects/index.js:307:14)
    at dispatchHttpRequest (.../node_modules/axios/lib/adapters/http.js:179:25)
    at new Promise (<anonymous>)
    at httpAdapter (.../node_modules/axios/lib/adapters/http.js:21:10)
    at dispatchRequest (.../node_modules/axios/lib/core/dispatchRequest.js:52:10)

Since I'm working on a public JIRA instance and my use case does only require read but not write access, I'd expect this module to allow me to use the APIs that are also publicly available.

This used to work without issues in jira-connector.

I found that the issue simply was that the getAuthentication helper function returned undefined if no authentication was specified. Replacing this undefined with an empty string solved the issue.

There was a test that explicitly checked for this undefined (which I changed in this PR), so I'm not sure if this was intentional and this issue is deeper in the core of axios?

@MrRefactoring
Copy link
Owner

Do I understand correctly that initialization looks like this:

const client = new Client({ host: '...' })

@MrRefactoring
Copy link
Owner

I got repro

@MrRefactoring
Copy link
Owner

I think we need to change the logic in the sendRequest method:

public async sendRequest(request: AxiosRequestConfig, callback?: Callback): Promise<any> {
    try {
      request.headers = request.headers || {};

      const authorization = request.headers.Authorization || getAuthentication(this.config, request);

      if (!!authorization) {
        request.headers.Authorization = authorization;
      }

      const response = await this.requestInstance.request(request);
...

@MrRefactoring MrRefactoring self-requested a review August 6, 2020 14:04
@violine1101
Copy link
Contributor Author

Do I understand correctly that initialization looks like this:

const client = new Client({ host: '...' })

Yes, that's what's what causes the crash.

I think we need to change the logic in the sendRequest method:

From what I can tell, that should work too, yeah.

@MrRefactoring
Copy link
Owner

Do I understand correctly that initialization looks like this:

const client = new Client({ host: '...' })

Yes, that's what's what causes the crash.

I think we need to change the logic in the sendRequest method:

From what I can tell, that should work too, yeah.

Will you make changes or should I do it?

@violine1101
Copy link
Contributor Author

I've committed your suggestion to my branch 👍

@MrRefactoring MrRefactoring merged commit 68f3b02 into MrRefactoring:master Aug 6, 2020
@MrRefactoring
Copy link
Owner

Thank you for your contribution!

@MrRefactoring
Copy link
Owner

Fixed in version 1.6.1

@MrRefactoring MrRefactoring added the bug Indicates a reported issue or malfunction that needs fixing. label Aug 6, 2020
@SPGoding SPGoding deleted the allow-no-auth branch October 29, 2020 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates a reported issue or malfunction that needs fixing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants