github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/crypt/crypt_test.go (about)

     1  // Test Crypt filesystem interface
     2  package crypt_test
     3  
     4  import (
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/rclone/rclone/backend/crypt"
    10  	_ "github.com/rclone/rclone/backend/drive" // for integration tests
    11  	_ "github.com/rclone/rclone/backend/local"
    12  	_ "github.com/rclone/rclone/backend/swift" // for integration tests
    13  	"github.com/rclone/rclone/fs/config/obscure"
    14  	"github.com/rclone/rclone/fstest"
    15  	"github.com/rclone/rclone/fstest/fstests"
    16  )
    17  
    18  // TestIntegration runs integration tests against the remote
    19  func TestIntegration(t *testing.T) {
    20  	if *fstest.RemoteName == "" {
    21  		t.Skip("Skipping as -remote not set")
    22  	}
    23  	fstests.Run(t, &fstests.Opt{
    24  		RemoteName:                   *fstest.RemoteName,
    25  		NilObject:                    (*crypt.Object)(nil),
    26  		UnimplementableFsMethods:     []string{"OpenWriterAt"},
    27  		UnimplementableObjectMethods: []string{"MimeType"},
    28  	})
    29  }
    30  
    31  // TestStandard runs integration tests against the remote
    32  func TestStandard(t *testing.T) {
    33  	if *fstest.RemoteName != "" {
    34  		t.Skip("Skipping as -remote set")
    35  	}
    36  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-standard")
    37  	name := "TestCrypt"
    38  	fstests.Run(t, &fstests.Opt{
    39  		RemoteName: name + ":",
    40  		NilObject:  (*crypt.Object)(nil),
    41  		ExtraConfig: []fstests.ExtraConfigItem{
    42  			{Name: name, Key: "type", Value: "crypt"},
    43  			{Name: name, Key: "remote", Value: tempdir},
    44  			{Name: name, Key: "password", Value: obscure.MustObscure("potato")},
    45  			{Name: name, Key: "filename_encryption", Value: "standard"},
    46  		},
    47  		UnimplementableFsMethods:     []string{"OpenWriterAt"},
    48  		UnimplementableObjectMethods: []string{"MimeType"},
    49  	})
    50  }
    51  
    52  // TestOff runs integration tests against the remote
    53  func TestOff(t *testing.T) {
    54  	if *fstest.RemoteName != "" {
    55  		t.Skip("Skipping as -remote set")
    56  	}
    57  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-off")
    58  	name := "TestCrypt2"
    59  	fstests.Run(t, &fstests.Opt{
    60  		RemoteName: name + ":",
    61  		NilObject:  (*crypt.Object)(nil),
    62  		ExtraConfig: []fstests.ExtraConfigItem{
    63  			{Name: name, Key: "type", Value: "crypt"},
    64  			{Name: name, Key: "remote", Value: tempdir},
    65  			{Name: name, Key: "password", Value: obscure.MustObscure("potato2")},
    66  			{Name: name, Key: "filename_encryption", Value: "off"},
    67  		},
    68  		UnimplementableFsMethods:     []string{"OpenWriterAt"},
    69  		UnimplementableObjectMethods: []string{"MimeType"},
    70  	})
    71  }
    72  
    73  // TestObfuscate runs integration tests against the remote
    74  func TestObfuscate(t *testing.T) {
    75  	if *fstest.RemoteName != "" {
    76  		t.Skip("Skipping as -remote set")
    77  	}
    78  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-obfuscate")
    79  	name := "TestCrypt3"
    80  	fstests.Run(t, &fstests.Opt{
    81  		RemoteName: name + ":",
    82  		NilObject:  (*crypt.Object)(nil),
    83  		ExtraConfig: []fstests.ExtraConfigItem{
    84  			{Name: name, Key: "type", Value: "crypt"},
    85  			{Name: name, Key: "remote", Value: tempdir},
    86  			{Name: name, Key: "password", Value: obscure.MustObscure("potato2")},
    87  			{Name: name, Key: "filename_encryption", Value: "obfuscate"},
    88  		},
    89  		SkipBadWindowsCharacters:     true,
    90  		UnimplementableFsMethods:     []string{"OpenWriterAt"},
    91  		UnimplementableObjectMethods: []string{"MimeType"},
    92  	})
    93  }