Skip to content

Stubbing out authentication #936

Description

@brainsiq

I have the gcloud module talking to a local cloud datastore using the gcd tool for automated testing but am finding that it only works if I provide real credentials from my google console. Is there a way to stub out the authentication process so I can use test credentials?

Activity

  1. stephenplusplus commented on Nov 10, 2015

    @stephenplusplus
    Contributor

    This should definitely be possible. Can you show me how you're getting the Dataset instance and the errors/signs that it's not working that you are getting?

  2. stephenplusplus commented on Nov 10, 2015

    @stephenplusplus
    Contributor

    I put together a test branch, please give it a shot and let me know how it goes!

    $ npm install --save stephenplusplus/gcloud-node#spp--gcd-no-auth
  3. brainsiq commented on Nov 10, 2015

    @brainsiq
    Author

    Thanks for the response. I'll give that branch a go tomorrow. So far I've just set the DATASTORE_HOST environment variable to my gcd server as I haven't come across any specific instructions for stubbing out the oAuth call that is made with the credentials.

  4. brainsiq commented on Nov 10, 2015

    @brainsiq
    Author

    I get an invalid_grant response out of the gcloud lib when calling dataset.save

  5. stephenplusplus commented on Nov 10, 2015

    @stephenplusplus
    Contributor

    So far I've just set the DATASTORE_HOST environment variable

    That's mainly what I was wondering. Our code currently isn't seeing that and turning off the auth step. Hopefully that branch resolves that.

  6. brainsiq commented on Nov 11, 2015

    @brainsiq
    Author

    Looks like this may now be turning off the auth step but breaking something else further down the line as when it comes to doing the save I get [Error: Invalid URI "undefined/datastore/v1beta2/datasets/suppliers/commit"]

    I found that this.apiEndpoint from the Dataset constructor needs to be set for the API calls. Seems fairly easy to fix but can't quite see, at the moment, how to write tests to ensure that both this.apiEndpoint and customEndpoint both get set correctly.

  7. stephenplusplus commented on Nov 11, 2015

    @stephenplusplus
    Contributor

    Oops, good catch. I just pushed a fix (hopefully).

    If this works, I'll probably re-think how this is written before sending a PR. It's getting a wee bit messy.

  8. brainsiq commented on Nov 11, 2015

    @brainsiq
    Author

    Yep that change seems to have done the trick.

    These are my thoughts on the tests/implementation (slightly naive perhaps given I don't know any of the rest of the code base), hope they're welcome 😄 ...

    I thought that with the current implementation the tests would be better just asserting that ds.apiEndpoint is set to the correct URL depending on the options/env, rather than testing the implementation of that private determineApiEndpoint_ function. And if determineApiEndpoint_ became just getCustomEndpoint then you shouldn't need to mutate the options parameter as a side effect. I did feel it also needs a test that when a custom endpoint is provided then it sets up the auth correctly as presumably that's why this slipped through the net. That was the main thing I couldn't work out how to do given the current state of things, so I guess you may want to tweak things further.

    Anyway. Thanks for your help! Can live with it making the live auth calls for the time being until you figure something out.

  9. stephenplusplus commented on Nov 11, 2015

    @stephenplusplus
    Contributor

    Of course, all thoughts are welcome. I will ping you when it's in the PR
    stage for more :)

    On Wednesday, November 11, 2015, Chris Impey [email protected]
    wrote:

    Yep that change seems to have done the trick.

    These are my thoughts on the tests/implementation (slightly naive perhaps
    given I don't know any of the rest of the code base), hope they're welcome [image:
    😄] ...

    I thought that with the current implementation the tests would be better
    just asserting that ds.apiEndpoint is set to the correct URL depending on
    the options/env, rather than testing the implementation of that private
    determineApiEndpoint_ function. And if determineApiEndpoint_ became just
    getCustomEndpoint then you shouldn't need to mutate the options parameter
    as a side effect. I did feel it also needs a test that when a custom
    endpoint is provided then it sets up the auth correctly as presumably
    that's why this slipped through the net. That was the main thing I couldn't
    work out how to do given the current state of things, so I guess you may
    want to tweak things further.

    Anyway. Thanks for your help! Can live with it making the live auth calls
    for the time being until you figure something out.

    —
    Reply to this email directly or view it on GitHub
    #936 (comment)
    .

  10. brainsiq commented on Nov 13, 2015

    @brainsiq
    Author

    Good work 👍

    When might this make it to npm?

  11. stephenplusplus commented on Nov 14, 2015

    @stephenplusplus
    Contributor

    I'll shoot for Wednesday/Thursday next week. Our code is in a bit of a transition state right now, we have a few more PRs to squeeze in. Will ping you when it's out!

  12. added a commit that references this issue on Feb 5, 2026
  13. added a commit that references this issue on Feb 17, 2026
  14. added a commit that references this issue on Mar 5, 2026
  15. added a commit that references this issue on Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions