Last active
April 5, 2023 18:09
-
-
Save jps3/cd1022c4382ae4043b1c8129970c1ad8 to your computer and use it in GitHub Desktop.
Jamf Pro API auth bearer token validator and helper tests javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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