- Notifications
You must be signed in to change notification settings - Fork923
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletionscmd/testidp/README.md
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# How to use | ||
Start the idp service: | ||
```bash | ||
$ go run main.go | ||
2024-01-10 16:48:01.415 [info] stdlib: 2024/01/10 10:48:01 IDP Issuer URL http://127.0.0.1:44517 | ||
2024-01-10 16:48:01.415 [info] stdlib: 2024/01/10 10:48:01 Oauth Flags | ||
2024-01-10 16:48:01.415 [info] stdlib: 2024/01/10 10:48:01 --external-auth-providers='[{"type":"fake","client_id":"f2df566b-a1c9-407a-8b75-480db45c6476","client_secret":"55aca4e3-7b94-44b6-9f45-ecb5e81c560d","auth_url":"http://127.0.0.1:44517/oauth2/authorize","token_url":"http://127.0.0.1:44517/oauth2/token","validate_url":"http://127.0.0.1:44517/oauth2/userinfo","scopes":["openid","email","profile"]}]' | ||
2024-01-10 16:48:01.415 [info] stdlib: 2024/01/10 10:48:01 Press Ctrl+C to exit | ||
``` | ||
Then use the flag into your coderd instance: | ||
```bash | ||
develop.sh -- --external-auth-providers='[{"type":"fake","client_id":"f2df566b-a1c9-407a-8b75-480db45c6476","client_secret":"55aca4e3-7b94-44b6-9f45-ecb5e81c560d","auth_url":"http://127.0.0.1:44517/oauth2/authorize","token_url":"http://127.0.0.1:44517/oauth2/token","validate_url":"http://127.0.0.1:44517/oauth2/userinfo","scopes":["openid","email","profile"]}]' | ||
``` |
58 changes: 58 additions & 0 deletionscmd/testidp/main.go
This file contains hidden or 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
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) | ||
} | ||
// 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("Coderd 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) | ||
// Block until ctl+c | ||
<-c | ||
log.Println("Closing") | ||
} | ||
} |
34 changes: 29 additions & 5 deletionscoderd/coderdtest/oidctest/idp.go
This file contains hidden or 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
9 changes: 4 additions & 5 deletionscodersdk/deployment.go
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.