Thursday, March 30, 2017

How to unit test 3rd party API endpoints that need access_token?

I'm developing a backend API that consumes Github's API to retrieve some repos and do some stuff with it. Also I'm using Codeship CI, so all my data need to be in the code in order to be properly built.

There's a route in my backend /api/github/repos that takes an Github access_token as parameter and consumes https://api.github.com/user/repos endpoint which lists all logged user repositories.

My doubt is: how do I unit test this route? I cannot write my access_token in the unit test since it's sensitive data and I'm storing it in Github public repository nor I can seed that data to a database because the access_token will still be written in the code. Where should I keep my access_token? Is there another approach?

I'm developing in PHP using Laravel framework but as you can see this problem is language independent.



via Rodrigo Souza

Advertisement