-
Notifications
You must be signed in to change notification settings - Fork 102
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
Avoid panics in NewSharedKeyCredential #63
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @zezha-msft
Thanks for pushing a PR to start fixing the issue raised in #59 😄
I took a look through and whilst I don't work on this library - I've spotted some errors which aren't being handled and crashes that are possible which I thought are worth raising (perhaps less so for the tests, but certainly for the examples).
Hope that's helpful - thanks!
2018-03-28/azblob/zt_test.go
Outdated
@@ -1246,7 +1246,7 @@ func (s *aztestsSuite) TestContainerSetPermissionsPublicAccessContainer(c *chk.C | |||
|
|||
func (s *aztestsSuite) TestContainerSetPermissionsACLSinglePolicy(c *chk.C) { | |||
bsu := getBSU() | |||
credentials := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) | |||
credential, _ := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this check to ensure there's no error returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can check the error and panic. The test would have failed anyway if the credential was invalid, but I see that a panic here makes debugging easier.
2018-03-28/azblob/zt_test.go
Outdated
@@ -561,7 +561,7 @@ func (s *aztestsSuite) TestCreateBlobURLWithSnapshotAndSAS(c *chk.C) { | |||
blobURL, blobName := getBlockBlobURL(c, containerURL) | |||
|
|||
currentTime := time.Now().UTC() | |||
credential := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) | |||
credential, _ := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this check to ensure there's no error returned?
@@ -1151,7 +1156,7 @@ func ExampleListBlobsHierarchy() { | |||
accountName, accountKey := accountInfo() | |||
|
|||
// Use your Storage account's name and key to create a credential object; this is used to access your account. | |||
credential := azblob.NewSharedKeyCredential(accountName, accountKey) | |||
credential, _ := azblob.NewSharedKeyCredential(accountName, accountKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is an example (and thus a recommended way of using this library) - shouldn't this be checking that the error object returned is nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok!
@@ -1082,7 +1087,7 @@ func ExampleLeaseContainer() { | |||
accountName, accountKey := accountInfo() | |||
|
|||
// Use your Storage account's name and key to create a credential object; this is used to access your account. | |||
credential := azblob.NewSharedKeyCredential(accountName, accountKey) | |||
credential, _ := azblob.NewSharedKeyCredential(accountName, accountKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is an example (and thus a recommended way of using this library) - shouldn't this be checking that the error object returned is nil?
@@ -1052,7 +1056,8 @@ func ExampleUploadStreamToBlockBlob() { | |||
|
|||
// Create a BlockBlobURL object to a blob in the container (we assume the container already exists). | |||
u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net/mycontainer/BigBlockBlob.bin", accountName)) | |||
blockBlobURL := azblob.NewBlockBlobURL(*u, azblob.NewPipeline(azblob.NewSharedKeyCredential(accountName, accountKey), azblob.PipelineOptions{})) | |||
credential, _ := azblob.NewSharedKeyCredential(accountName, accountKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is an example (and thus a recommended way of using this library) - shouldn't this be checking that the error object returned is nil?
@@ -278,7 +278,7 @@ func ExampleAccountSASSignatureValues() { | |||
accountName, accountKey := accountInfo() | |||
|
|||
// Use your Storage account's name and key to create a credential object; this is required to sign a SAS. | |||
credential := azblob.NewSharedKeyCredential(accountName, accountKey) | |||
credential, _ := azblob.NewSharedKeyCredential(accountName, accountKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is an example (and thus a recommended way of working with this library) - shouldn't this error be handled?
@@ -32,7 +32,7 @@ func Example() { | |||
accountName, accountKey := accountInfo() | |||
|
|||
// Use your Storage account's name and key to create a credential object; this is used to access your account. | |||
credential := azblob.NewSharedKeyCredential(accountName, accountKey) | |||
credential, _ := azblob.NewSharedKeyCredential(accountName, accountKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is an example (and thus a recommended way of working with this library) - shouldn't this error be handled?
2018-03-28/azblob/zt_test.go
Outdated
@@ -1784,11 +1784,11 @@ func (s *aztestsSuite) TestBlobStartCopyUsingSASSrc(c *chk.C) { | |||
blobURL, blobName := createNewBlockBlob(c, containerURL) | |||
|
|||
// Create sas values for the source blob | |||
credentials := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) | |||
credential, _ := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this check to ensure there's no error returned?
2018-03-28/azblob/zt_test.go
Outdated
@@ -1830,8 +1830,8 @@ func (s *aztestsSuite) TestBlobStartCopyUsingSASDest(c *chk.C) { | |||
// Generate SAS on the source | |||
serviceSASValues := azblob.BlobSASSignatureValues{ExpiryTime: time.Now().Add(time.Hour).UTC(), | |||
Permissions: azblob.BlobSASPermissions{Read: true, Write: true, Create: true}.String(), ContainerName: containerName, BlobName: blobName} | |||
credentials := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) | |||
queryParams := serviceSASValues.NewSASQueryParameters(credentials) | |||
credential, _ := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this check to ensure there's no error returned?
2018-03-28/azblob/zt_test.go
Outdated
@@ -1845,11 +1845,11 @@ func (s *aztestsSuite) TestBlobStartCopyUsingSASDest(c *chk.C) { | |||
copyBlobURL, copyBlobName := getBlockBlobURL(c, copyContainerURL) | |||
|
|||
// Generate Sas for the destination | |||
credentials = azblob.NewSharedKeyCredential(os.Getenv("SECONDARY_ACCOUNT_NAME"), os.Getenv("SECONDARY_ACCOUNT_KEY")) | |||
credential, _ = azblob.NewSharedKeyCredential(os.Getenv("SECONDARY_ACCOUNT_NAME"), os.Getenv("SECONDARY_ACCOUNT_KEY")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this check to ensure there's no error returned?
9805d4f
to
0802cea
Compare
0802cea
to
d795ea3
Compare
No description provided.