Skip to content

Commit

Permalink
Merge pull request #292 from IBM-Cloud/promote-v0.8.1
Browse files Browse the repository at this point in the history
Release v0.8.1 promotion
  • Loading branch information
jorge-ibm authored Dec 6, 2021
2 parents 8c9d8a6 + a0af811 commit d2042cb
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 25 deletions.
62 changes: 52 additions & 10 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "^.secrets.baseline$",
"lines": null
},
"generated_at": "2021-12-02T17:22:21Z",
"generated_at": "2021-12-06T21:18:44Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -188,10 +188,18 @@
],
"bluemix/configuration/core_config/bx_config_test.go": [
{
"hashed_secret": "9507a758af9127f99a700b500657fd558b705dc9",
"hashed_secret": "90919f1360ad1f9525de7a64061c105d061df1c8",
"is_secret": false,
"is_verified": false,
"line_number": 303,
"line_number": 377,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "40e89785a3d6a88c5ef431f64ec054b1d39e186e",
"is_secret": false,
"is_verified": false,
"line_number": 393,
"type": "JSON Web Token",
"verified_result": null
}
Expand All @@ -201,7 +209,7 @@
"hashed_secret": "e85f6eac7402c010fcea6b6d024a1875ac213f99",
"is_secret": false,
"is_verified": false,
"line_number": 221,
"line_number": 241,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -211,51 +219,85 @@
"hashed_secret": "8d8e2cec529a6f642c25b4473b2adc8cde563c36",
"is_secret": false,
"is_verified": false,
"line_number": 12,
"line_number": 18,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "de89e230a57dd89a612cc8439c00d0001ffa6389",
"is_secret": false,
"is_verified": false,
"line_number": 15,
"line_number": 21,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "6a4b65a72c0da02a03007867d9838f4a256a384b",
"is_secret": false,
"is_verified": false,
"line_number": 21,
"line_number": 27,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "42be9b0e85dc9f0fcb42c69058b133fd23dfde2b",
"is_secret": false,
"is_verified": false,
"line_number": 27,
"line_number": 33,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "73f596843cdc77ecc6a0a4cdc5b5d89071ad1b79",
"is_secret": false,
"is_verified": false,
"line_number": 31,
"line_number": 37,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "63a47776714d85556701c61dd731a302ed132385",
"hashed_secret": "c017c618a0ef5209f2cbbb367a7c68eb0404e043",
"is_secret": false,
"is_verified": false,
"line_number": 47,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "6160045cbf6bfe6c1669311f5720fd73cbe56243",
"is_secret": false,
"is_verified": false,
"line_number": 57,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "63a47776714d85556701c61dd731a302ed132385",
"is_secret": false,
"is_verified": false,
"line_number": 76,
"type": "Hex High Entropy String",
"verified_result": null
}
],
"bluemix/configuration/core_config/uaa_token_test.go": [
{
"hashed_secret": "c017c618a0ef5209f2cbbb367a7c68eb0404e043",
"is_secret": false,
"is_verified": false,
"line_number": 22,
"type": "JSON Web Token",
"verified_result": null
},
{
"hashed_secret": "3c1dbf49c59ee96e6a9ac90bea40471c0cb8b4f1",
"is_secret": false,
"is_verified": false,
"line_number": 32,
"type": "JSON Web Token",
"verified_result": null
}
],
"bluemix/env.go": [
{
"hashed_secret": "33e5e588d24c979db687c950cf004784e95ddb1b",
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ We follow the offical [CodeReviewComments](https://github.com/golang/go/wiki/Cod
Make sure you have good unit test. Run `go test -cover $(go list ./...)`, and ensure coverage is above 80% for major packages (aka packages other than i18n, fakes, docs...).

#### Secret Detection
This project uses the IBM Detect Secrets Module. Install the module, by following these [instructions](https://github.com/ibm/detect-secrets#installupgrade-module). Once installed, enable the pre-commit secret detection hook by following these [instructions](https://github.com/ibm/detect-secrets#installupgrade-module) to ensure no secrets are committed to this repo.
This project uses the IBM Detect Secrets Module. Install the module, by following these [instructions](https://github.com/ibm/detect-secrets#installupgrade-module). Once installed, enable the pre-commit secret detection hook by following these [instructions](https://github.com/ibm/detect-secrets#prevention-pre-commit-hook) to ensure no secrets are committed to this repo.


#### Commit Message
Expand Down
33 changes: 28 additions & 5 deletions bluemix/configuration/core_config/bx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,34 @@ func (c *bxConfig) IAMID() (guid string) {
return
}

func (c *bxConfig) IsLoggedIn() (loggedIn bool) {
c.read(func() {
loggedIn = c.data.IAMToken != ""
})
return
// IsLoggedIn will check if the user is logged in. To determine if the user is logged in both the
// token and the refresh token will be checked
// If token is near expiration or expired, and a refresh token is present attempt to refresh the token.
// If token refresh was successful, check if the new IAM token is valid. If valid, user is logged in,
// otherwise user can be considered logged out. If refresh failed, then user is considered logged out.
// If no refresh token is present, and token is expired, then user is considered logged out.
func (c *bxConfig) IsLoggedIn() bool {
if token, refresh := c.IAMToken(), c.IAMRefreshToken(); token != "" || refresh != "" {
iamTokenInfo := NewIAMTokenInfo(token)
if iamTokenInfo.hasExpired() && refresh != "" {
repo := newRepository(c, nil)
if _, err := repo.RefreshIAMToken(); err != nil {
return false
}
// Check again to make sure that the new token has not expired
if iamTokenInfo = NewIAMTokenInfo(c.IAMToken()); iamTokenInfo.hasExpired() {
return false
}

return true
} else if iamTokenInfo.hasExpired() && refresh == "" {
return false
} else {
return true
}
}

return false
}

func (c *bxConfig) CurrentAccount() (account models.Account) {
Expand Down
86 changes: 85 additions & 1 deletion bluemix/configuration/core_config/bx_config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package core_config_test

import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"

Expand Down Expand Up @@ -298,9 +301,80 @@ func TestVPCCRITokenURL(t *testing.T) {
t.Cleanup(cleanupConfigFiles)
}

func TestIsLoggedIn(t *testing.T) {
config := prepareConfigForCLI(`{"UsageStatsEnabledLastUpdate": "2021-11-29T12:23:43.519017+08:00","UsageStatsEnabled": true}`, t)
refresh := "eyJhbGciOiJydCJ9.eyJzZXNzaW9uX2lkIjoiQy02YzUzN2U3My0wMjAxLTQ0YmUtODZlZC0zMDY0YTUwMTMwNGYiLCJpYW1faWQiOiJJQk1pZC02NjYwMDE1UktKIiwiYWNjb3VudF9pZCI6IjYwOWMxNGI4NjhmNTQ1OWM5YmZkOGJhOGI4OTZiYmE5In0._WLlp2iYEpA9PTStswtoXPj5GhiXwrEB0EhEVIF-SKu34qL3-gmfjIeN7RJGT--nwvmuuDfcVIdhA2j7MCmjPqk8YUMVmvR38YY7pA81sk7ynBOeJSg_D2_QCDeH-p1waMZlmedvzhVhSJAqhsorQYOR5GMDmz-kiwOwbQ0ewBiX7Bkc5S_49spJG7T5qsBwLjd8EXjCFGGWg4MS-QXn1SnVKBJZ82VyRL8lSTrMCC2DGseA29ptLOhJJldKVjDrfgLAMDILge08Rbz5NZplwkBRLYT7bvMEaO1cj_we6Ya1DPEO70rYkkIJQ-UtYyOUMEVw4th1LKHkKFNYK4oR_it5DpX-w4jTi49yNbV8ragDtmfUQy1dQ7Vxv5Xc7IsF8htFboxtqYwqRi32M0821ftoGYbxZRX2W6BsijmaBUpE_iaBV39ulFJrvW4Uf9fp-GvjIkZo3iJZN8syrr6LQ_RicB73s3rhZ1tIA7i4w7lapSMAgGH2xqufh6Ca31YBN7Karj0Cy6CxX_2P4aLPlAgZL4qJK3gOz56h4hWqmLhurjf5bn0uPXznPAMAoWpim2MwvSSH3EPRbxUyqGusUe-AXhcY_bTjfWibQJ59wL0q3s6gNwkn1y0RKEdlGoc1ofkJU9XfJWc_HCrZ0Lkq5PjQDqk3WkhkxxVGuD92Ha8LNlff-u_hqpBT86nV7D9r9das0vl4etJA6QK8FJMJ5prRNUpKmrVWpMJrSCQr5o8FxvB94yC0H6FcvDTdIl2slVtOO5wtOkaqtcHL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NkODA3MGI1NDY4IiwiaWRlbnRpZmllciI6IlByb2ZpbGUtOTQ0OTdkMGQtMmFjMy00MWJmLWE5OTMtYTQ5ZDFiMTQ2MjdjIiwibmFtZSI6Ik15IFByb2ZpbGUiLCJzdWIiOiJQcm9maWxlLTk0NDk3ZDBkLTJhYzMtNDFiZi1hOTkzLWE0OWQxYjE0NjI3YyIsInN1Yl90eXBlIjoiUHJvZmlsZSIsImF1dGhuIjp7InN1YiI6ImNybjp2MTpzdGFnaW5nOnB1YmxpYzppYW0taWRlbnRpdHk6OmEvMThlMzAyMDc0OWNlNDc0NGIwYjQ3MjQ2NmQ2MWZkYjQ6OmNvbXB1dGVyZXNvdXJjZTpGYWtlLUNvbXB1dGUtUmVzb3VyY2UiLCJpYW1faWQiOiJjcm4tY3JuOnYxOnN0YWdpbmc6cHVibGljOmlhbS1pZGVudGl0eTo6YS8xOGUzMDIwNzQ5Y2U0NzQ0YjBiNDcyNDY2ZDYxZmRiNDo6Y29tcHV0ZXJlc291cmNlOkZha2UtQ29tcHV0ZS1SZXNvdXJjZSIsIm5hbWUiOiJteV9jb21wdXRlX3Jlc291cmNlIn0sImFjY291bnQiOnsiYm91bmRhcnkiOiJnbG9iYWwiLCJ2YWxpZCI6dHJ1ZSwiYnNzIjoiZmFrZV9ic3MifSwiaWF0IjoxNjI5OTI5NDYzLCJleHAiOjgwMjk5MzMwNjMsImlzcyI6Imh0dHBzOi8vaWFtLmNsb3VkLmlibS5jb20vaWRlbnRpdHkiLCJncmFudF90eXBlIjoidXJuOmlibTpwYXJhbXM6b2F1dGg6Z3JhbnQtdHlwZTpjci10b2tlbiIsInNjb3BlIjoiaWJtIG9wZW5pZCIsImNsaWVudF9pZCI6ImJ4In0.ACeIK_8Wi0QmgQ19w4J2OA0OKgC4zb6M6PuGuPTEY_E"
tests := []struct {
name string
token string
newToken string
refresh string
newRefresh string
isLoggedIn bool
}{
{
name: "token is expired and refresh token is present",
token: expiredToken,
newToken: "bearer " + newToken, // on refresh the bearer header is append to the token
refresh: refresh,
newRefresh: refresh,
isLoggedIn: true,
},
{
name: "token is expired and refresh token is NOT present",
token: expiredToken,
newToken: expiredToken,
refresh: "",
newRefresh: "",
isLoggedIn: false,
},
{
name: "token is not expired",
token: newToken,
newToken: newToken,
refresh: refresh,
newRefresh: refresh,
isLoggedIn: true,
},
{
name: "token is not expired and refresh is NOT present",
token: newToken,
newToken: newToken,
refresh: "",
newRefresh: "",
isLoggedIn: true,
},
}

IAMEndpoints := models.Endpoints{}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprintf(w, "{\"access_token\": \"%s\", \"refresh_token\": \"%s\", \"token_type\": \"bearer\"}", newToken, refresh)
}))
defer ts.Close()

IAMEndpoints.PublicEndpoint = ts.URL
IAMEndpoints.PrivateEndpoint = ts.URL
IAMEndpoints.PrivateVPCEndpoint = ts.URL

config.SetIAMToken(test.token)
config.SetIAMRefreshToken(test.refresh)
config.SetIAMEndpoints(IAMEndpoints)
assert.Equal(t, test.isLoggedIn, config.IsLoggedIn())
assert.Equal(t, test.newToken, config.IAMToken())
assert.Equal(t, test.newRefresh, config.IAMRefreshToken())
t.Cleanup(cleanupConfigFiles)
})
}
}

func TestIsLoggedInAsProfile(t *testing.T) {
config := prepareConfigForCLI(`{"UsageStatsEnabledLastUpdate": "2020-03-29T12:23:43.519017+08:00","UsageStatsEnabled": true}`, t)
testIAMCRTokenData := "Bearer eyJraWQiOiIyMDE3MTAzMC0wMDowMDowMCIsImFsZyI6IlJTMjU2In0.ewoJImlhbV9pZCI6ICJpYW0tUHJvZmlsZS05NDQ5N2QwZC0yYWMzLTQxYmYtYTk5My1hNDlkMWIxNDYyN2MiLAoJImlkIjogIklCTWlkLXRlc3QiLAoJInJlYWxtaWQiOiAiaWFtIiwKCSJqdGkiOiAiMDRkMjBiMjUtZWUyZC00MDBmLTg2MjMtOGNkODA3MGI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Zha2UtQ29tcHV0ZS1SZXNvdXJjZSIsIm5hbWUiOiJteV9jb21wdXRlX3Jlc291cmNlIn0sImFjY291bnQiOnsiYm91bmRhcnkiOiJnbG9iYWwiLCJ2YWxpZCI6dHJ1ZSwiYnNzIjoiZmFrZV9ic3MifSwiaWF0IjoxNjI5OTI5NDYzLCJleHAiOjgwMjk5MzMwNjMsImlzcyI6Imh0dHBzOi8vaWFtLmNsb3VkLmlibS5jb20vaWRlbnRpdHkiLCJncmFudF90eXBlIjoidXJuOmlibTpwYXJhbXM6b2F1dGg6Z3JhbnQtdHlwZTpjci10b2tlbiIsInNjb3BlIjoiaWJtIG9wZW5pZCIsImNsaWVudF9pZCI6ImJ4In0.ACeIK_8Wi0QmgQ19w4J2OA0OKgC4zb6M6PuGuPTEY_E"

// check
checkUsageStats(true, true, config, t)
Expand All @@ -313,6 +387,16 @@ func TestIsLoggedInAsProfile(t *testing.T) {
t.Cleanup(cleanupConfigFiles)
}

func TestIsLoggedInWithServiceID(t *testing.T) {
// Setup
config := prepareConfigForCLI(`{"UsageStatsEnabledLastUpdate": "2020-03-29T12:23:43.519017+08:00","UsageStatsEnabled": true}`, t)
testIAMCRTokenData := "eyJraWQiOiIyMDE3MTAzMC0wMDowMDowMCIsImFsZyI6IkhTMjU2In0.eyJpYW1faWQiOiJpYW0tUHJvZmlsZS05NDQ5N2QwZC0yYWMzLTQxYmYtYTk5My1hNDlkMWIxNDYyN2MiLCJpZCI6IklCTWlkLXRlc3QiLCJyZWFsbWlkIjoiaWFtIiwianRpIjoiMDRkMjBiMjUtZWUyZC00MDBmLTg2MjMtOGNkODA3MGI1NDY4IiwiaWRlbnRpZmllciI6IlByb2ZpbGUtOTQ0OTdkMGQtMmFjMy00MWJmLWE5OTMtYTQ5ZDFiMTQ2MjdjIiwibmFtZSI6Ik15IFNlcnZpY2UiLCJzdWIiOiJQcm9maWxlLTk0NDk3ZDBkLTJhYzMtNDFiZi1hOTkzLWE0OWQxYjE0NjI3YyIsInN1Yl90eXBlIjoiU2VydmljZUlkIiwiYXV0aG4iOnsic3ViIjoiY3JuOnYxOnN0YWdpbmc6cHVibGljOmlhbS1pZGVudGl0eTo6YS8xOGUzMDIwNzQ5Y2U0NzQ0YjBiNDcyNDY2ZDYxZmRiNDo6Y29tcHV0ZXJlc291cmNlOkZha2UtQ29tcHV0ZS1SZXNvdXJjZSIsImlhbV9pZCI6ImNybi1jcm46djE6c3RhZ2luZzpwdWJsaWM6aWFtLWlkZW50aXR5OjphLzE4ZTMwMjA3NDljZTQ3NDRiMGI0NzI0NjZkNjFmZGI0Ojpjb21wdXRlcmVzb3VyY2U6RmFrZS1Db21wdXRlLVJlc291cmNlIiwibmFtZSI6Im15X2NvbXB1dGVfcmVzb3VyY2UifSwiYWNjb3VudCI6eyJib3VuZGFyeSI6Imdsb2JhbCIsInZhbGlkIjp0cnVlLCJic3MiOiJmYWtlX2JzcyJ9LCJpYXQiOjE2Mjk5Mjk0NjMsImV4cCI6MjYyOTkzMzA2MywiaXNzIjoiaHR0cHM6Ly9pYW0uY2xvdWQuaWJtLmNvbS9pZGVudGl0eSIsImdyYW50X3R5cGUiOiJ1cm46aWJtOnBhcmFtczpvYXV0aDpncmFudC10eXBlOmNyLXRva2VuIiwic2NvcGUiOiJpYm0gb3BlbmlkIiwiY2xpZW50X2lkIjoiYngifQ.n3WF2O2KMmhW0nBDN2CooOwgcSDGI2qK858BzaHB6YI"
config.SetIAMToken(testIAMCRTokenData)

// Assertions
assert.True(t, config.IsLoggedInWithServiceID())
}

func TestIsLoggedInAsCRI(t *testing.T) {
config := prepareConfigForCLI(`{"UsageStatsEnabledLastUpdate": "2020-03-29T12:23:43.519017+08:00","UsageStatsEnabled": true}`, t)

Expand Down
Loading

0 comments on commit d2042cb

Please sign in to comment.