-
Notifications
You must be signed in to change notification settings - Fork 898
chore: allow running fake idp with coderd dev #11555
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"testing" | ||
|
||
"github.com/golang-jwt/jwt/v4" | ||
|
||
"github.com/coder/coder/v2/coderd/coderdtest/oidctest" | ||
) | ||
|
||
func main() { | ||
testing.Init() | ||
_ = flag.Set("test.timeout", "0") | ||
|
||
flag.Parse() | ||
|
||
// This is just a way to run tests outside go test | ||
testing.Main(func(pat, str string) (bool, error) { | ||
return true, nil | ||
}, []testing.InternalTest{ | ||
{ | ||
Name: "Run Fake IDP", | ||
F: RunIDP(), | ||
}, | ||
}, nil, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels weird, but I understand you did it to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt werid saying Another idea I had was to just implement the So I'd have to embed an actual testing.T struct? It just also has it's "jankiness", so just went with this for now. |
||
} | ||
|
||
// RunIDP needs the testing.T because our oidctest package requires the | ||
// testing.T. | ||
func RunIDP() func(t *testing.T) { | ||
return func(t *testing.T) { | ||
idp := oidctest.NewFakeIDP(t, | ||
oidctest.WithServing(), | ||
oidctest.WithStaticUserInfo(jwt.MapClaims{}), | ||
oidctest.WithDefaultIDClaims(jwt.MapClaims{}), | ||
) | ||
id, sec := idp.AppCredentials() | ||
prov := idp.WellknownConfig() | ||
|
||
log.Println("IDP Issuer URL", idp.IssuerURL()) | ||
log.Println("Oauth Flags") | ||
log.Printf(`--external-auth-providers='[{"type":"fake","client_id":"%s","client_secret":"%s","auth_url":"%s","token_url":"%s","validate_url":"%s","scopes":["openid","email","profile"]}]'`, | ||
id, sec, prov.AuthURL, prov.TokenURL, prov.UserInfoURL, | ||
) | ||
|
||
log.Println("Press Ctrl+C to exit") | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
select { | ||
case <-c: | ||
log.Println("Closing") | ||
} | ||
} | ||
} |
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 could be moved to
cmd/testidp
. I think it would be confusing to have packages that can be built sprinkled within the source tree.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 call 👍