-
Notifications
You must be signed in to change notification settings - Fork 16
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
Credentials Middleware tests #461
Conversation
accountKey: { | ||
type: "string", | ||
description: "The account key to use when calling Fauna", | ||
required: false, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when are customers going to want/need to use this flag? for operations vs frontdoor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We called it out in the design phase as something that can be set by the user. I don't know the use case yet, but I know we have a UI page to allow users to create one of these keys so who knows how they might want to use those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also said we want flag parity for everything. It's probably the "right" thing to do.
It would allow you to use the cli even if frontdoor login was failing but the rest of frontdoor was okay, right?
it("refreshes database key", async () => { | ||
v10runQueryFromString | ||
.onCall(0) | ||
.rejects({ | ||
error: {}, | ||
httpStatus: 401, | ||
}) | ||
.onCall(1) | ||
.resolves({ | ||
data: [], | ||
}); | ||
makeAccountRequest | ||
.withArgs( | ||
sinon.match({ | ||
path: sinon.match(/\/databases\/keys/), | ||
method: "POST", | ||
}), | ||
) | ||
.resolves({ | ||
secret: "new-secret", | ||
}); | ||
await run(`query "Database.all()" -d us-std --no-color`, container); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a pretty cool test :)
// We need to use the original implementation of runQueryFromString to ensure it hits | ||
// faunaClientV10.runQueryFromString which is where we force the 401 and test the refresh | ||
// logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good comment
// Instead of mocking `fs` to return certain values in each test, let the middleware | ||
// read files in the actual filesystem. | ||
const setCredsFiles = (accessKeys, secretKeys) => { | ||
fs.mkdirSync(credsDir, { recursive: true }); | ||
fs.writeFileSync( | ||
`${credsDir}/access_keys`, | ||
JSON.stringify(accessKeys, null, 2), | ||
); | ||
fs.writeFileSync( | ||
`${credsDir}/secret_keys`, | ||
JSON.stringify(secretKeys, null, 2), | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
how much effort would it be to mock out these calls and have this function change the mock behaviors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a decent chunk. Idea here was "set and forget" and let the middleware get
and save
as often as it needs to. Then at the end of the test I could assert that a certain key was used, knowing things were persisted correctly along the way. (e.g. line 311 in this file, seeing as getOrRefreshKey
first goes to keyStore.get()
)
I wanted to avoid a function here that worries about fs.readFileSync.onCall(x) -> spit out the new key instead of old one
etc.
Might be overthinking it :P
Ticket(s): FE-6174
Problem
No tests for the credentials middleware
Solution
Result
Test coverage
Testing
Suite passes