Add test for http bearer-token auth by Santosh1176 · Pull Request #1058 · fluxcd/source-controller
@Santosh1176 thanks for taking this up.
Looks like the tests pass because there's no real authentication check being performed in the git test server.
In
| if len(tt.server.username+tt.server.password) > 0 { | |
| server.Auth(tt.server.username, tt.server.password) | |
| } |
, authentication is only configured when username or password is set. In the test case you've added, since they are not set, the git test server doesn't have authentication enabled.
As mentioned in #1005 (comment) , the gittestserver needs to be updated to use the new gitkit which has bearer token support and update the gitkit AuthFunc in the GitServer in https://github.com/fluxcd/pkg/blob/5382a4b12ebd84c10c63433e63e379eae6bde153/gittestserver/server.go#L153-L155 to check and compare the provided bearer token if any. May also need to add a new function, maybe with the signature
func (s *GitServer) WithBearerAuth(token string) *GitServer
to set the bearer token in the GitServer similar to GitServer.Auth(). Please create a PR against https://github.com/fluxcd/pkg/ for this.
After all that, this gitrepository test can be updated to configure the gittestserver to set the bearer token when it's used in the test case.
The bearer token support in gitkit got merged a few days ago, refer fluxcd/gitkit@a88e269 . For now, you can pin the go dependency to that commit when updating the gittestserver dependencies. Once we have a tagged release, you can update it to a specific tag.
@aryan9600 can we do a new gitkit release with the bearer token support?