forked from remote/oauth2
Changes requested by @lsirac
This commit is contained in:
@@ -56,7 +56,7 @@ func CreateExecutableCredential(ec ExecutableConfig, config *Config, ctx context
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type subjectTokenResponse struct {
|
type executableResponse struct {
|
||||||
Version *int `json:"version"`
|
Version *int `json:"version"`
|
||||||
Success *bool `json:"success"`
|
Success *bool `json:"success"`
|
||||||
TokenType *string `json:"token_type"`
|
TokenType *string `json:"token_type"`
|
||||||
@@ -68,7 +68,7 @@ type subjectTokenResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseSubjectToken(response []byte) (string, error) {
|
func parseSubjectToken(response []byte) (string, error) {
|
||||||
var result subjectTokenResponse
|
var result executableResponse
|
||||||
if err := json.Unmarshal(response, &result); err != nil {
|
if err := json.Unmarshal(response, &result); err != nil {
|
||||||
return "", errors.New("oauth2/google: Unable to parse response JSON.")
|
return "", errors.New("oauth2/google: Unable to parse response JSON.")
|
||||||
}
|
}
|
||||||
@@ -132,10 +132,6 @@ func parseSubjectToken(response []byte) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cs executableCredentialSource) subjectToken() (string, error) {
|
func (cs executableCredentialSource) subjectToken() (string, error) {
|
||||||
if token, ok := cs.getTokenFromInMemoryCaching(); ok {
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if token, ok := cs.getTokenFromOutputFile(); ok {
|
if token, ok := cs.getTokenFromOutputFile(); ok {
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
@@ -143,11 +139,6 @@ func (cs executableCredentialSource) subjectToken() (string, error) {
|
|||||||
return cs.getTokenFromExecutableCommand()
|
return cs.getTokenFromExecutableCommand()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs executableCredentialSource) getTokenFromInMemoryCaching() (string, bool) {
|
|
||||||
// TODO
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs executableCredentialSource) getTokenFromOutputFile() (string, bool) {
|
func (cs executableCredentialSource) getTokenFromOutputFile() (string, bool) {
|
||||||
// TODO
|
// TODO
|
||||||
return "", false
|
return "", false
|
||||||
@@ -176,11 +167,7 @@ func (cs executableCredentialSource) getNewEnvironmentVariables() map[string]str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cs.isInteractive() {
|
|
||||||
result["GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE"] = "1"
|
|
||||||
} else {
|
|
||||||
result["GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE"] = "0"
|
result["GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE"] = "0"
|
||||||
}
|
|
||||||
|
|
||||||
if cs.OutputFile != "" {
|
if cs.OutputFile != "" {
|
||||||
result["GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE"] = cs.OutputFile
|
result["GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE"] = cs.OutputFile
|
||||||
@@ -189,11 +176,6 @@ func (cs executableCredentialSource) getNewEnvironmentVariables() map[string]str
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs executableCredentialSource) isInteractive() bool {
|
|
||||||
// Currently, executableCredentialSource does not yet support interactive mode.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs executableCredentialSource) getTokenFromExecutableCommand() (string, error) {
|
func (cs executableCredentialSource) getTokenFromExecutableCommand() (string, error) {
|
||||||
// For security reasons, we need our consumers to set this environment variable to allow executables to be run.
|
// For security reasons, we need our consumers to set this environment variable to allow executables to be run.
|
||||||
if getenv("GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES") != "1" {
|
if getenv("GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES") != "1" {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func areSlicesEquivalent(a, b []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OUTER:
|
OUTER:
|
||||||
for i, aa := range a {
|
for _, aa := range a {
|
||||||
for _, bb := range b {
|
for _, bb := range b {
|
||||||
if aa == bb {
|
if aa == bb {
|
||||||
continue OUTER
|
continue OUTER
|
||||||
@@ -315,7 +315,7 @@ func TestRetrieveExecutableSubjectTokenMissingVersion(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -361,7 +361,7 @@ func TestRetrieveExecutableSubjectTokenMissingSuccess(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -407,7 +407,7 @@ func TestRetrieveExecutableSubjectTokenUnsuccessfulResponseWithFields(t *testing
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(false),
|
Success: Bool(false),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
Code: String("404"),
|
Code: String("404"),
|
||||||
@@ -456,7 +456,7 @@ func TestRetrieveExecutableSubjectTokenUnsuccessfulResponseWithCode(t *testing.T
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(false),
|
Success: Bool(false),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
Code: String("404"),
|
Code: String("404"),
|
||||||
@@ -504,7 +504,7 @@ func TestRetrieveExecutableSubjectTokenUnsuccessfulResponseWithMessage(t *testin
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(false),
|
Success: Bool(false),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
Message: String("Token Not Found"),
|
Message: String("Token Not Found"),
|
||||||
@@ -552,7 +552,7 @@ func TestRetrieveExecutableSubjectTokenUnsuccessfulResponseWithoutFields(t *test
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(false),
|
Success: Bool(false),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
})
|
})
|
||||||
@@ -599,7 +599,7 @@ func TestRetrieveExecutableSubjectTokenNewerVersion(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(2),
|
Version: Int(2),
|
||||||
})
|
})
|
||||||
@@ -646,7 +646,7 @@ func TestRetrieveExecutableSubjectTokenExpired(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
ExpirationTime: Int64(now().Unix() - 1),
|
ExpirationTime: Int64(now().Unix() - 1),
|
||||||
@@ -695,7 +695,7 @@ func TestRetrieveExecutableSubjectTokenJwt(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
ExpirationTime: Int64(now().Unix() + 3600),
|
ExpirationTime: Int64(now().Unix() + 3600),
|
||||||
@@ -746,7 +746,7 @@ func TestRetrieveExecutableSubjectTokenJwtMissingIdToken(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
ExpirationTime: Int64(now().Unix() + 3600),
|
ExpirationTime: Int64(now().Unix() + 3600),
|
||||||
@@ -795,7 +795,7 @@ func TestRetrieveExecutableSubjectTokenIdToken(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
ExpirationTime: Int64(now().Unix() + 3600),
|
ExpirationTime: Int64(now().Unix() + 3600),
|
||||||
@@ -846,7 +846,7 @@ func TestRetrieveExecutableSubjectTokenSaml(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
ExpirationTime: Int64(now().Unix() + 3600),
|
ExpirationTime: Int64(now().Unix() + 3600),
|
||||||
@@ -897,7 +897,7 @@ func TestRetrieveExecutableSubjectTokenSamlMissingResponse(t *testing.T) {
|
|||||||
deadline, deadlineSet := now(), false
|
deadline, deadlineSet := now(), false
|
||||||
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
runCommand = func(ctx context.Context, command string, env []string) ([]byte, error) {
|
||||||
deadline, deadlineSet = ctx.Deadline()
|
deadline, deadlineSet = ctx.Deadline()
|
||||||
return json.Marshal(subjectTokenResponse{
|
return json.Marshal(executableResponse{
|
||||||
Success: Bool(true),
|
Success: Bool(true),
|
||||||
Version: Int(1),
|
Version: Int(1),
|
||||||
ExpirationTime: Int64(now().Unix() + 3600),
|
ExpirationTime: Int64(now().Unix() + 3600),
|
||||||
|
|||||||
Reference in New Issue
Block a user