@@ -14,17 +14,18 @@ import (
14
14
"time"
15
15
16
16
"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
+
17
22
"github.com/coder/coder/coderd"
18
23
"github.com/coder/coder/coderd/coderdtest"
19
24
"github.com/coder/coder/codersdk"
20
25
"github.com/coder/coder/cryptorand"
21
26
"github.com/coder/coder/database"
22
27
"github.com/coder/coder/provisioner/echo"
23
28
"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"
28
29
)
29
30
30
31
func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity (t * testing.T ) {
@@ -37,7 +38,7 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
37
38
client := coderdtest .New (t , & coderdtest.Options {
38
39
GoogleTokenValidator : validator ,
39
40
})
40
- _ , err := client .WorkspaceAgentAuthenticateGoogleInstanceIdentity (context .Background (), "" , createMetadataClient (signedKey ))
41
+ _ , err := client .AuthenticateWorkspaceAgentUsingGoogleCloudIdentity (context .Background (), "" , createMetadataClient (signedKey ))
41
42
var apiErr * codersdk.Error
42
43
require .ErrorAs (t , err , & apiErr )
43
44
require .Equal (t , http .StatusUnauthorized , apiErr .StatusCode ())
@@ -51,7 +52,7 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
51
52
client := coderdtest .New (t , & coderdtest.Options {
52
53
GoogleTokenValidator : validator ,
53
54
})
54
- _ , err := client .WorkspaceAgentAuthenticateGoogleInstanceIdentity (context .Background (), "" , createMetadataClient (signedKey ))
55
+ _ , err := client .AuthenticateWorkspaceAgentUsingGoogleCloudIdentity (context .Background (), "" , createMetadataClient (signedKey ))
55
56
var apiErr * codersdk.Error
56
57
require .ErrorAs (t , err , & apiErr )
57
58
require .Equal (t , http .StatusNotFound , apiErr .StatusCode ())
@@ -91,7 +92,7 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
91
92
require .NoError (t , err )
92
93
coderdtest .AwaitWorkspaceProvisionJob (t , client , user .Organization , firstHistory .ProvisionJobID )
93
94
94
- _ , err = client .WorkspaceAgentAuthenticateGoogleInstanceIdentity (context .Background (), "" , createMetadataClient (signedKey ))
95
+ _ , err = client .AuthenticateWorkspaceAgentUsingGoogleCloudIdentity (context .Background (), "" , createMetadataClient (signedKey ))
95
96
require .NoError (t , err )
96
97
})
97
98
}
@@ -117,7 +118,7 @@ func createMetadataClient(signedKey string) *metadata.Client {
117
118
}
118
119
119
120
// 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 ) {
121
122
keyID , err := cryptorand .String (12 )
122
123
require .NoError (t , err )
123
124
if claims == nil {
@@ -132,11 +133,11 @@ func createSignedToken(t *testing.T, instanceID string, claims *jwt.MapClaims) (
132
133
}
133
134
token := jwt .NewWithClaims (jwt .SigningMethodRS256 , claims )
134
135
token .Header ["kid" ] = keyID
135
- privateKey , err : = rsa .GenerateKey (rand .Reader , 2048 )
136
+ privateKey , err = rsa .GenerateKey (rand .Reader , 2048 )
136
137
require .NoError (t , err )
137
- signed , err : = token .SignedString (privateKey )
138
+ signedKey , err = token .SignedString (privateKey )
138
139
require .NoError (t , err )
139
- return signed , keyID , privateKey
140
+ return signedKey , keyID , privateKey
140
141
}
141
142
142
143
// Create's a validator that verifies against the provided private key.
0 commit comments