Skip to content
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

fix: file download #33

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ logger, _ := zap.NewProduction()
// create a zap logger wrapper
zapLogger := logging.NewZapLogger(logger)
```
## Unit Tests
```
go-client-library-passwordsafe\api\authentication> go test
go-client-library-passwordsafe\api\managed_account> go test
go-client-library-passwordsafe\api\secrets> go test
```

## License
This software is distributed under the Massachusetts Institute of Technology (MIT) License. See `LICENSE.txt` for more information.
Expand Down
10 changes: 5 additions & 5 deletions TestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func main() {
retryMaxElapsedTimeMinutes := 2

// validate inputs
errors_in_inputs := utils.ValidateInputs(clientId, clientSecret, apiUrl, clientTimeOutInSeconds, &separator, verifyCa, zapLogger, certificate, certificateKey)
errorsInInputs := utils.ValidateInputs(clientId, clientSecret, apiUrl, clientTimeOutInSeconds, &separator, verifyCa, zapLogger, certificate, certificateKey)

if errors_in_inputs != nil {
if errorsInInputs != nil {
return
}

Expand All @@ -61,8 +61,8 @@ func main() {
}

// getting secrets
secretList := strings.Split(paths, ",")
gotSecrets, _ := secretObj.GetSecrets(secretList, separator)
secretPaths := strings.Split(paths, ",")
gotSecrets, _ := secretObj.GetSecrets(secretPaths, separator)

// WARNING: Do not log secrets in production code, the following log statement logs test secrets for testing purposes:
zapLogger.Info(fmt.Sprintf("%v", gotSecrets))
Expand All @@ -71,7 +71,7 @@ func main() {
gotSecret, _ := secretObj.GetSecret("fake/text1", separator)

// WARNING: Do not log secrets in production code, the following log statement logs test secrets for testing purposes:
zapLogger.Info(fmt.Sprintf("%v", gotSecret))
zapLogger.Info(fmt.Sprintf("Secret Test: %v", gotSecret))

// instantiating managed account obj
manageAccountObj, _ := managed_accounts.NewManagedAccountObj(*authenticate, zapLogger)
Expand Down
16 changes: 8 additions & 8 deletions api/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ func NewSecretObj(authentication authentication.AuthenticationObj, logger loggin
}

// GetSecrets returns secret value for a path and title list.
func (secretObj *SecretObj) GetSecrets(secretsList []string, separator string) (map[string]string, error) {
func (secretObj *SecretObj) GetSecrets(secretPaths []string, separator string) (map[string]string, error) {
if separator == "" {
separator = ""
}
return secretObj.GetSecretFlow(secretsList, separator)
return secretObj.GetSecretFlow(secretPaths, separator)
}

// GetSecret returns secret value for a specific path and title.
func (secretObj *SecretObj) GetSecret(secretPath string, separator string) (string, error) {
secretList := []string{}
secrets, _ := secretObj.GetSecretFlow(append(secretList, secretPath), separator)
secretPaths := []string{}
secrets, _ := secretObj.GetSecretFlow(append(secretPaths, secretPath), separator)
secretValue := secrets[secretPath]
return secretValue, nil
}
Expand Down Expand Up @@ -73,9 +73,9 @@ func (secretObj *SecretObj) GetSecretFlow(secretsToRetrieve []string, separator
}

secretDictionary[secretToRetrieve] = fileSecretContent
} else {
secretDictionary[secretToRetrieve] = secret.Password
}
secretDictionary[secretToRetrieve] = secret.Password

}

return secretDictionary, nil
Expand Down Expand Up @@ -126,7 +126,7 @@ func (secretObj *SecretObj) SecretGetSecretByPath(secretPath string, secretTitle

if len(SecretObjectList) == 0 {
scode = 404
err = fmt.Errorf("Error %v: StatusCode: %v ", "SecretGetSecretByPath, Secret was not found", scode)
err = fmt.Errorf("error %v: StatusCode: %v ", "SecretGetSecretByPath, Secret was not found", scode)
return entities.Secret{}, err
}

Expand All @@ -137,7 +137,7 @@ func (secretObj *SecretObj) SecretGetSecretByPath(secretPath string, secretTitle
// and returns file secret value.
func (secretObj *SecretObj) SecretGetFileSecret(secretId string, endpointPath string) (string, error) {
messageLog := fmt.Sprintf("%v %v", "GET", endpointPath)
secretObj.log.Debug(messageLog)
secretObj.log.Debug(messageLog + "file/download")

var body io.ReadCloser
var technicalError error
Expand Down
8 changes: 4 additions & 4 deletions api/secrets/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestSecretFlow(t *testing.T) {
http.NotFound(w, r)
}
})),
response: "credential_in_sub_3_password",
response: "fake_password",
}

authenticate.ApiUrl = testConfig.server.URL + "/"
Expand Down Expand Up @@ -198,14 +198,14 @@ func TestSecretFlow_SecretNotFound(t *testing.T) {
http.NotFound(w, r)
}
})),
response: "Error SecretGetSecretByPath, Secret was not found: StatusCode: 404 ",
response: "error SecretGetSecretByPath, Secret was not found: StatusCode: 404 ",
}

authenticate.ApiUrl = testConfig.server.URL + "/"
secretObj, _ := NewSecretObj(*authenticate, zapLogger)

secretList := strings.Split("oauthgrp_nocert/Test1,oauthgrp_nocert/client_id", ",")
_, err := secretObj.GetSecretFlow(secretList, "/")
secretPaths := strings.Split("oauthgrp_nocert/Test1,oauthgrp_nocert/client_id", ",")
_, err := secretObj.GetSecretFlow(secretPaths, "/")

if err == nil {
t.Errorf("Test case Failed: %v", err)
Expand Down
Loading