@@ -14,17 +14,18 @@ import (
1414 "time"
1515
1616 "cloud.google.com/go/compute/metadata"
17+ "github.com/golang-jwt/jwt"
18+ "github.com/stretchr/testify/require"
19+ "google.golang.org/api/idtoken"
20+ "google.golang.org/api/option"
21+
1722 "github.com/coder/coder/coderd"
1823 "github.com/coder/coder/coderd/coderdtest"
1924 "github.com/coder/coder/codersdk"
2025 "github.com/coder/coder/cryptorand"
2126 "github.com/coder/coder/database"
2227 "github.com/coder/coder/provisioner/echo"
2328 "github.com/coder/coder/provisionersdk/proto"
24- "github.com/golang-jwt/jwt"
25- "github.com/stretchr/testify/require"
26- "google.golang.org/api/idtoken"
27- "google.golang.org/api/option"
2829)
2930
3031func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity (t * testing.T ) {
@@ -37,7 +38,7 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
3738 client := coderdtest .New (t , & coderdtest.Options {
3839 GoogleTokenValidator : validator ,
3940 })
40- _ , err := client .WorkspaceAgentAuthenticateGoogleInstanceIdentity (context .Background (), "" , createMetadataClient (signedKey ))
41+ _ , err := client .AuthenticateWorkspaceAgentUsingGoogleCloudIdentity (context .Background (), "" , createMetadataClient (signedKey ))
4142 var apiErr * codersdk.Error
4243 require .ErrorAs (t , err , & apiErr )
4344 require .Equal (t , http .StatusUnauthorized , apiErr .StatusCode ())
@@ -51,7 +52,7 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
5152 client := coderdtest .New (t , & coderdtest.Options {
5253 GoogleTokenValidator : validator ,
5354 })
54- _ , err := client .WorkspaceAgentAuthenticateGoogleInstanceIdentity (context .Background (), "" , createMetadataClient (signedKey ))
55+ _ , err := client .AuthenticateWorkspaceAgentUsingGoogleCloudIdentity (context .Background (), "" , createMetadataClient (signedKey ))
5556 var apiErr * codersdk.Error
5657 require .ErrorAs (t , err , & apiErr )
5758 require .Equal (t , http .StatusNotFound , apiErr .StatusCode ())
@@ -91,7 +92,7 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
9192 require .NoError (t , err )
9293 coderdtest .AwaitWorkspaceProvisionJob (t , client , user .Organization , firstHistory .ProvisionJobID )
9394
94- _ , err = client .WorkspaceAgentAuthenticateGoogleInstanceIdentity (context .Background (), "" , createMetadataClient (signedKey ))
95+ _ , err = client .AuthenticateWorkspaceAgentUsingGoogleCloudIdentity (context .Background (), "" , createMetadataClient (signedKey ))
9596 require .NoError (t , err )
9697 })
9798}
@@ -117,7 +118,7 @@ func createMetadataClient(signedKey string) *metadata.Client {
117118}
118119
119120// Create's a signed JWT with a randomly generated private key.
120- func createSignedToken (t * testing.T , instanceID string , claims * jwt.MapClaims ) (string , string , * rsa.PrivateKey ) {
121+ func createSignedToken (t * testing.T , instanceID string , claims * jwt.MapClaims ) (signedKey string , keyID string , privateKey * rsa.PrivateKey ) {
121122 keyID , err := cryptorand .String (12 )
122123 require .NoError (t , err )
123124 if claims == nil {
@@ -132,11 +133,11 @@ func createSignedToken(t *testing.T, instanceID string, claims *jwt.MapClaims) (
132133 }
133134 token := jwt .NewWithClaims (jwt .SigningMethodRS256 , claims )
134135 token .Header ["kid" ] = keyID
135- privateKey , err : = rsa .GenerateKey (rand .Reader , 2048 )
136+ privateKey , err = rsa .GenerateKey (rand .Reader , 2048 )
136137 require .NoError (t , err )
137- signed , err : = token .SignedString (privateKey )
138+ signedKey , err = token .SignedString (privateKey )
138139 require .NoError (t , err )
139- return signed , keyID , privateKey
140+ return signedKey , keyID , privateKey
140141}
141142
142143// Create's a validator that verifies against the provided private key.
0 commit comments