Skip to content

Instantly share code, notes, and snippets.

@jps3
Last active April 5, 2023 18:09
Show Gist options
  • Save jps3/cd1022c4382ae4043b1c8129970c1ad8 to your computer and use it in GitHub Desktop.
Save jps3/cd1022c4382ae4043b1c8129970c1ad8 to your computer and use it in GitHub Desktop.
Jamf Pro API auth bearer token validator and helper tests javascript
/*
* Jamf Pro API auth bearer token validator/helper
*
* Paste into:
* auth
* Create a token based on other authentication details (basic, etc.)
* Tests (tab)
*
* (Assumes you have an environment already set up with variables defined for
* baseUrl, basicAuthUsername, basicAuthPassword, and bearerToken)
*
*/
pm.test("Status code is 200", () => {
pm.expect(pm.response.code).to.eql(200);
pm.test("The response has all properties", () => {
const jsonData = pm.response.json();
pm.expect(jsonData).to.be.an('object');
pm.expect(jsonData).to.have.all.keys('token', 'expires');
pm.expect(jsonData.token).to.be.a('string');
pm.expect(jsonData.expires).to.be.a('number');
});
pm.test("Set and clear environment variables", () => {
// pm.environment.set('basicAuthUsername', '');
pm.environment.set('basicAuthPassword', '');
pm.environment.set('bearerToken', pm.response.json().token);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment