@@ -1555,10 +1555,8 @@ func TestCopyVolume(t *testing.T) {
15551555 VolumeContentSource : & volumecontensource ,
15561556 }
15571557
1558- ctx := context .Background ()
1559-
15601558 expectedErr := status .Errorf (codes .InvalidArgument , "copy volume from volumeSnapshot is not supported" )
1561- err := d .copyVolume (ctx , req , "" , "" , "core.windows.net" )
1559+ err := d .copyVolume (req , "" , nil , "" , "core.windows.net" )
15621560 if ! reflect .DeepEqual (err , expectedErr ) {
15631561 t .Errorf ("Unexpected error: %v" , err )
15641562 }
@@ -1587,10 +1585,8 @@ func TestCopyVolume(t *testing.T) {
15871585 VolumeContentSource : & volumecontensource ,
15881586 }
15891587
1590- ctx := context .Background ()
1591-
15921588 expectedErr := status .Errorf (codes .NotFound , "error parsing volume id: \" unit-test\" , should at least contain two #" )
1593- err := d .copyVolume (ctx , req , "" , "dstContainer" , "core.windows.net" )
1589+ err := d .copyVolume (req , "" , nil , "dstContainer" , "core.windows.net" )
15941590 if ! reflect .DeepEqual (err , expectedErr ) {
15951591 t .Errorf ("Unexpected error: %v" , err )
15961592 }
@@ -1619,10 +1615,8 @@ func TestCopyVolume(t *testing.T) {
16191615 VolumeContentSource : & volumecontensource ,
16201616 }
16211617
1622- ctx := context .Background ()
1623-
16241618 expectedErr := fmt .Errorf ("srcContainerName() or dstContainerName(dstContainer) is empty" )
1625- err := d .copyVolume (ctx , req , "" , "dstContainer" , "core.windows.net" )
1619+ err := d .copyVolume (req , "" , nil , "dstContainer" , "core.windows.net" )
16261620 if ! reflect .DeepEqual (err , expectedErr ) {
16271621 t .Errorf ("Unexpected error: %v" , err )
16281622 }
@@ -1651,43 +1645,8 @@ func TestCopyVolume(t *testing.T) {
16511645 VolumeContentSource : & volumecontensource ,
16521646 }
16531647
1654- ctx := context .Background ()
1655-
16561648 expectedErr := fmt .Errorf ("srcContainerName(fileshare) or dstContainerName() is empty" )
1657- err := d .copyVolume (ctx , req , "" , "" , "core.windows.net" )
1658- if ! reflect .DeepEqual (err , expectedErr ) {
1659- t .Errorf ("Unexpected error: %v" , err )
1660- }
1661- },
1662- },
1663- {
1664- name : "AADClientSecret shouldn't be nil or useManagedIdentityExtension must be set to true when accountSASToken is empty" ,
1665- testFunc : func (t * testing.T ) {
1666- d := NewFakeDriver ()
1667- d .cloud = & azure.Cloud {}
1668- mp := map [string ]string {}
1669-
1670- volumeSource := & csi.VolumeContentSource_VolumeSource {
1671- VolumeId : "vol_1#f5713de20cde511e8ba4900#fileshare#" ,
1672- }
1673- volumeContentSourceVolumeSource := & csi.VolumeContentSource_Volume {
1674- Volume : volumeSource ,
1675- }
1676- volumecontensource := csi.VolumeContentSource {
1677- Type : volumeContentSourceVolumeSource ,
1678- }
1679-
1680- req := & csi.CreateVolumeRequest {
1681- Name : "unit-test" ,
1682- VolumeCapabilities : stdVolumeCapabilities ,
1683- Parameters : mp ,
1684- VolumeContentSource : & volumecontensource ,
1685- }
1686-
1687- ctx := context .Background ()
1688-
1689- expectedErr := fmt .Errorf ("service principle or managed identity are both not set" )
1690- err := d .copyVolume (ctx , req , "" , "dstContainer" , "core.windows.net" )
1649+ err := d .copyVolume (req , "" , nil , "" , "core.windows.net" )
16911650 if ! reflect .DeepEqual (err , expectedErr ) {
16921651 t .Errorf ("Unexpected error: %v" , err )
16931652 }
@@ -1728,10 +1687,8 @@ func TestCopyVolume(t *testing.T) {
17281687
17291688 d .azcopy .ExecCmd = m
17301689
1731- ctx := context .Background ()
1732-
17331690 var expectedErr error
1734- err := d .copyVolume (ctx , req , "sastoken" , "dstContainer" , "core.windows.net" )
1691+ err := d .copyVolume (req , "sastoken" , nil , "dstContainer" , "core.windows.net" )
17351692 if ! reflect .DeepEqual (err , expectedErr ) {
17361693 t .Errorf ("Unexpected error: %v" , err )
17371694 }
@@ -1773,10 +1730,8 @@ func TestCopyVolume(t *testing.T) {
17731730
17741731 d .azcopy .ExecCmd = m
17751732
1776- ctx := context .Background ()
1777-
17781733 var expectedErr error
1779- err := d .copyVolume (ctx , req , "sastoken" , "dstContainer" , "core.windows.net" )
1734+ err := d .copyVolume (req , "sastoken" , nil , "dstContainer" , "core.windows.net" )
17801735 if ! reflect .DeepEqual (err , expectedErr ) {
17811736 t .Errorf ("Unexpected error: %v" , err )
17821737 }
@@ -1995,7 +1950,7 @@ func TestAuthorizeAzcopyWithIdentity(t *testing.T) {
19951950 }
19961951}
19971952
1998- func TestGetSASToken (t * testing.T ) {
1953+ func TestGetAzcopyAuth (t * testing.T ) {
19991954 testCases := []struct {
20001955 name string
20011956 testFunc func (t * testing.T )
@@ -2014,14 +1969,14 @@ func TestGetSASToken(t *testing.T) {
20141969 ctx := context .Background ()
20151970 expectedAccountSASToken := ""
20161971 expectedErr := fmt .Errorf ("could not find accountkey or azurestorageaccountkey field in secrets" )
2017- accountSASToken , err := d .getSASToken (ctx , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
1972+ accountSASToken , _ , err := d .getAzcopyAuth (ctx , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
20181973 if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
20191974 t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
20201975 }
20211976 },
20221977 },
20231978 {
2024- name : "failed to test azcopy list command " ,
1979+ name : "generate sas token using account key " ,
20251980 testFunc : func (t * testing.T ) {
20261981 d := NewFakeDriver ()
20271982 d .cloud = & azure.Cloud {
@@ -2033,21 +1988,10 @@ func TestGetSASToken(t *testing.T) {
20331988 }
20341989 secrets := map [string ]string {
20351990 defaultSecretAccountName : "accountName" ,
1991+ defaultSecretAccountKey : "YWNjb3VudGtleQo=" ,
20361992 }
2037- ctrl := gomock .NewController (t )
2038- defer ctrl .Finish ()
2039-
2040- m := util .NewMockEXEC (ctrl )
2041- listStr := "error"
2042- m .EXPECT ().RunCommand (gomock .Any (), gomock .Any ()).Return (listStr , fmt .Errorf ("error" ))
2043-
2044- d .azcopy .ExecCmd = m
2045-
2046- ctx := context .Background ()
2047- expectedAccountSASToken := ""
2048- expectedErr := fmt .Errorf ("azcopy list command failed with error(%v): %v" , fmt .Errorf ("error" ), "error" )
2049- accountSASToken , err := d .getSASToken (ctx , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
2050- if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
1993+ accountSASToken , _ , err := d .getAzcopyAuth (context .Background (), "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
1994+ if ! reflect .DeepEqual (err , nil ) || ! strings .Contains (accountSASToken , "?se=" ) {
20511995 t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
20521996 }
20531997 },
@@ -2067,19 +2011,10 @@ func TestGetSASToken(t *testing.T) {
20672011 defaultSecretAccountName : "accountName" ,
20682012 defaultSecretAccountKey : "fakeValue" ,
20692013 }
2070- ctrl := gomock .NewController (t )
2071- defer ctrl .Finish ()
2072-
2073- m := util .NewMockEXEC (ctrl )
2074- listStr := "RESPONSE 403: 403 This request is not authorized to perform this operation using this permission.\n ERROR CODE: AuthorizationPermissionMismatch"
2075- m .EXPECT ().RunCommand (gomock .Any (), gomock .Any ()).Return (listStr , nil )
20762014
2077- d .azcopy .ExecCmd = m
2078-
2079- ctx := context .Background ()
20802015 expectedAccountSASToken := ""
20812016 expectedErr := status .Errorf (codes .Internal , fmt .Sprintf ("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s" , "accountName" , "decode account key: illegal base64 data at input byte 8" ))
2082- accountSASToken , err := d .getSASToken ( ctx , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
2017+ accountSASToken , _ , err := d .getAzcopyAuth ( context . Background () , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
20832018 if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
20842019 t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
20852020 }
@@ -2100,7 +2035,7 @@ func TestGetSASToken(t *testing.T) {
21002035 ctx := context .Background ()
21012036 expectedAccountSASToken := ""
21022037 expectedErr := status .Errorf (codes .Internal , fmt .Sprintf ("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s" , "accountName" , "decode account key: illegal base64 data at input byte 8" ))
2103- accountSASToken , err := d .getSASToken (ctx , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
2038+ accountSASToken , _ , err := d .getAzcopyAuth (ctx , "accountName" , "" , "core.windows.net" , & azure.AccountOptions {}, secrets , "secretsName" , "secretsNamespace" )
21042039 if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
21052040 t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
21062041 }
0 commit comments