@@ -163,6 +163,67 @@ func TestBlobClient_FGetObject(t *testing.T) {
163
163
g .Expect (f ).To (Equal ([]byte (testFileData )))
164
164
}
165
165
166
+ func TestBlobClientSASKey_FGetObject (t * testing.T ) {
167
+ g := NewWithT (t )
168
+
169
+ tempDir := t .TempDir ()
170
+
171
+ // create a client with the shared key
172
+ client , err := NewClient (testBucket .DeepCopy (), testSecret .DeepCopy ())
173
+ g .Expect (err ).ToNot (HaveOccurred ())
174
+ g .Expect (client ).ToNot (BeNil ())
175
+
176
+ g .Expect (client .CanGetAccountSASToken ()).To (BeTrue ())
177
+
178
+ // Generate test container name.
179
+ testContainer := generateString (testContainerGenerateName )
180
+
181
+ // Create test container.
182
+ ctx , timeout := context .WithTimeout (context .Background (), testTimeout )
183
+ defer timeout ()
184
+ g .Expect (createContainer (ctx , client , testContainer )).To (Succeed ())
185
+ t .Cleanup (func () {
186
+ g .Expect (deleteContainer (context .Background (), client , testContainer )).To (Succeed ())
187
+ })
188
+
189
+ // Create test blob.
190
+ ctx , timeout = context .WithTimeout (context .Background (), testTimeout )
191
+ defer timeout ()
192
+ g .Expect (createBlob (ctx , client , testContainer , testFile , testFileData ))
193
+
194
+ localPath := filepath .Join (tempDir , testFile )
195
+
196
+ // use the shared key client to create a SAS key for the account
197
+ sasKey , err := client .GetSASToken (azblob.AccountSASResourceTypes {Object : true , Container : true },
198
+ azblob.AccountSASPermissions {List : true , Read : true },
199
+ azblob.AccountSASServices {Blob : true },
200
+ time .Now (),
201
+ time .Now ().Add (48 * time .Hour ))
202
+ g .Expect (err ).ToNot (HaveOccurred ())
203
+ g .Expect (sasKey ).ToNot (BeEmpty ())
204
+
205
+ // the sdk returns the full SAS url e.g test.blob.core.windows.net/?<actual-sas-token>
206
+ sasKey = strings .TrimPrefix (sasKey , testBucket .Spec .Endpoint + "/" )
207
+ testSASKeySecret := corev1.Secret {
208
+ Data : map [string ][]byte {
209
+ sasKeyField : []byte (sasKey ),
210
+ },
211
+ }
212
+
213
+ sasKeyClient , err := NewClient (testBucket .DeepCopy (), testSASKeySecret .DeepCopy ())
214
+ g .Expect (err ).ToNot (HaveOccurred ())
215
+
216
+ // Test if blob exists using sasKey.
217
+ ctx , timeout = context .WithTimeout (context .Background (), testTimeout )
218
+ defer timeout ()
219
+ _ , err = sasKeyClient .FGetObject (ctx , testContainer , testFile , localPath )
220
+
221
+ g .Expect (err ).ToNot (HaveOccurred ())
222
+ g .Expect (localPath ).To (BeARegularFile ())
223
+ f , _ := os .ReadFile (localPath )
224
+ g .Expect (f ).To (Equal ([]byte (testFileData )))
225
+ }
226
+
166
227
func TestBlobClient_FGetObject_NotFoundErr (t * testing.T ) {
167
228
g := NewWithT (t )
168
229
0 commit comments