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

Core.cs has a pretty bad null pointer error #141

Closed
alexsawicki opened this issue Aug 14, 2015 · 0 comments · Fixed by #142
Closed

Core.cs has a pretty bad null pointer error #141

alexsawicki opened this issue Aug 14, 2015 · 0 comments · Fixed by #142

Comments

@alexsawicki
Copy link

I was trying to use the API, and for some reason, I was getting a null pointer exception from anything that I was running. I eventually found the stack trace, and found that it was throwing the error inside of the GetPasswordOrTokenAuthHeader function. So, switched over to using the APIToken, and I could call methods just fine, no null pointers. So, I was curious, and begun looking at the code here, and found this method in core.cs:

        protected string GetPasswordOrTokenAuthHeader()
        {
            if (!string.IsNullOrEmpty(ApiToken.Trim()))
                return GetAuthHeader(User + "/token", ApiToken);
            else if (!string.IsNullOrEmpty(Password.Trim()))
                return GetAuthHeader(User, Password);
            else
                return string.Format("Bearer {0}", OAuthToken);
        }

Now, if the ApiToken is null, that first if statement will always fail. It will ALWAYS throw a null pointer, and so you can never get to the password authentication. I do not have time to pull down this code, fix this error, and push it back up, so if someone could change the above section of code to:

protected string GetPasswordOrTokenAuthHeader()
        {
            if (!(string.IsNullOrWhitespace(ApiToken)))
                return GetAuthHeader(User + "/token", ApiToken);
            else if (!string.IsNullOrWhitespace(Password.Trim()))
                return GetAuthHeader(User, Password);
            else
                return string.Format("Bearer {0}", OAuthToken);
        }

The string.IsNullOrWhitespace method, I believe, is what was intended here: you wanted to make sure that the APIToken wasn't just spaces either. This won't fail anytime someone tries to authenticate with username and password

Thanks!

mozts2005 added a commit that referenced this issue Aug 18, 2015
clean up ZendeskUrl fixed #139, fixed #141
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 a pull request may close this issue.

1 participant