@@ -1555,10 +1555,8 @@ func TestCopyVolume(t *testing.T) {
1555
1555
VolumeContentSource : & volumecontensource ,
1556
1556
}
1557
1557
1558
- ctx := context .Background ()
1559
-
1560
1558
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" )
1562
1560
if ! reflect .DeepEqual (err , expectedErr ) {
1563
1561
t .Errorf ("Unexpected error: %v" , err )
1564
1562
}
@@ -1587,10 +1585,8 @@ func TestCopyVolume(t *testing.T) {
1587
1585
VolumeContentSource : & volumecontensource ,
1588
1586
}
1589
1587
1590
- ctx := context .Background ()
1591
-
1592
1588
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" )
1594
1590
if ! reflect .DeepEqual (err , expectedErr ) {
1595
1591
t .Errorf ("Unexpected error: %v" , err )
1596
1592
}
@@ -1619,10 +1615,8 @@ func TestCopyVolume(t *testing.T) {
1619
1615
VolumeContentSource : & volumecontensource ,
1620
1616
}
1621
1617
1622
- ctx := context .Background ()
1623
-
1624
1618
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" )
1626
1620
if ! reflect .DeepEqual (err , expectedErr ) {
1627
1621
t .Errorf ("Unexpected error: %v" , err )
1628
1622
}
@@ -1651,43 +1645,8 @@ func TestCopyVolume(t *testing.T) {
1651
1645
VolumeContentSource : & volumecontensource ,
1652
1646
}
1653
1647
1654
- ctx := context .Background ()
1655
-
1656
1648
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" )
1691
1650
if ! reflect .DeepEqual (err , expectedErr ) {
1692
1651
t .Errorf ("Unexpected error: %v" , err )
1693
1652
}
@@ -1728,10 +1687,8 @@ func TestCopyVolume(t *testing.T) {
1728
1687
1729
1688
d .azcopy .ExecCmd = m
1730
1689
1731
- ctx := context .Background ()
1732
-
1733
1690
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" )
1735
1692
if ! reflect .DeepEqual (err , expectedErr ) {
1736
1693
t .Errorf ("Unexpected error: %v" , err )
1737
1694
}
@@ -1773,10 +1730,8 @@ func TestCopyVolume(t *testing.T) {
1773
1730
1774
1731
d .azcopy .ExecCmd = m
1775
1732
1776
- ctx := context .Background ()
1777
-
1778
1733
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" )
1780
1735
if ! reflect .DeepEqual (err , expectedErr ) {
1781
1736
t .Errorf ("Unexpected error: %v" , err )
1782
1737
}
@@ -1995,7 +1950,7 @@ func TestAuthorizeAzcopyWithIdentity(t *testing.T) {
1995
1950
}
1996
1951
}
1997
1952
1998
- func TestGetSASToken (t * testing.T ) {
1953
+ func TestGetAzcopyAuth (t * testing.T ) {
1999
1954
testCases := []struct {
2000
1955
name string
2001
1956
testFunc func (t * testing.T )
@@ -2014,14 +1969,14 @@ func TestGetSASToken(t *testing.T) {
2014
1969
ctx := context .Background ()
2015
1970
expectedAccountSASToken := ""
2016
1971
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" )
2018
1973
if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
2019
1974
t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
2020
1975
}
2021
1976
},
2022
1977
},
2023
1978
{
2024
- name : "failed to test azcopy list command " ,
1979
+ name : "generate sas token using account key " ,
2025
1980
testFunc : func (t * testing.T ) {
2026
1981
d := NewFakeDriver ()
2027
1982
d .cloud = & azure.Cloud {
@@ -2033,21 +1988,10 @@ func TestGetSASToken(t *testing.T) {
2033
1988
}
2034
1989
secrets := map [string ]string {
2035
1990
defaultSecretAccountName : "accountName" ,
1991
+ defaultSecretAccountKey : "YWNjb3VudGtleQo=" ,
2036
1992
}
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=" ) {
2051
1995
t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
2052
1996
}
2053
1997
},
@@ -2067,19 +2011,10 @@ func TestGetSASToken(t *testing.T) {
2067
2011
defaultSecretAccountName : "accountName" ,
2068
2012
defaultSecretAccountKey : "fakeValue" ,
2069
2013
}
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 )
2076
2014
2077
- d .azcopy .ExecCmd = m
2078
-
2079
- ctx := context .Background ()
2080
2015
expectedAccountSASToken := ""
2081
2016
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" )
2083
2018
if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
2084
2019
t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
2085
2020
}
@@ -2100,7 +2035,7 @@ func TestGetSASToken(t *testing.T) {
2100
2035
ctx := context .Background ()
2101
2036
expectedAccountSASToken := ""
2102
2037
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" )
2104
2039
if ! reflect .DeepEqual (err , expectedErr ) || ! reflect .DeepEqual (accountSASToken , expectedAccountSASToken ) {
2105
2040
t .Errorf ("Unexpected accountSASToken: %s, Unexpected error: %v" , accountSASToken , err )
2106
2041
}
0 commit comments