github.com/artpar/rclone@v1.67.3/backend/crypt/crypt_test.go (about)

     1  // Test Crypt filesystem interface
     2  package crypt_test
     3  
     4  import (
     5  	"os"
     6  	"path/filepath"
     7  	"runtime"
     8  	"testing"
     9  
    10  	"github.com/artpar/rclone/backend/crypt"
    11  	_ "github.com/artpar/rclone/backend/drive" // for integration tests
    12  	_ "github.com/artpar/rclone/backend/local"
    13  	_ "github.com/artpar/rclone/backend/swift" // for integration tests
    14  	"github.com/artpar/rclone/fs/config/obscure"
    15  	"github.com/artpar/rclone/fstest"
    16  	"github.com/artpar/rclone/fstest/fstests"
    17  )
    18  
    19  // TestIntegration runs integration tests against the remote
    20  func TestIntegration(t *testing.T) {
    21  	if *fstest.RemoteName == "" {
    22  		t.Skip("Skipping as -remote not set")
    23  	}
    24  	fstests.Run(t, &fstests.Opt{
    25  		RemoteName:                   *fstest.RemoteName,
    26  		NilObject:                    (*crypt.Object)(nil),
    27  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
    28  		UnimplementableObjectMethods: []string{"MimeType"},
    29  	})
    30  }
    31  
    32  // TestStandard runs integration tests against the remote
    33  func TestStandardBase32(t *testing.T) {
    34  	if *fstest.RemoteName != "" {
    35  		t.Skip("Skipping as -remote set")
    36  	}
    37  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-standard")
    38  	name := "TestCrypt"
    39  	fstests.Run(t, &fstests.Opt{
    40  		RemoteName: name + ":",
    41  		NilObject:  (*crypt.Object)(nil),
    42  		ExtraConfig: []fstests.ExtraConfigItem{
    43  			{Name: name, Key: "type", Value: "crypt"},
    44  			{Name: name, Key: "remote", Value: tempdir},
    45  			{Name: name, Key: "password", Value: obscure.MustObscure("potato")},
    46  			{Name: name, Key: "filename_encryption", Value: "standard"},
    47  		},
    48  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
    49  		UnimplementableObjectMethods: []string{"MimeType"},
    50  		QuickTestOK:                  true,
    51  	})
    52  }
    53  
    54  func TestStandardBase64(t *testing.T) {
    55  	if *fstest.RemoteName != "" {
    56  		t.Skip("Skipping as -remote set")
    57  	}
    58  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-standard")
    59  	name := "TestCrypt"
    60  	fstests.Run(t, &fstests.Opt{
    61  		RemoteName: name + ":",
    62  		NilObject:  (*crypt.Object)(nil),
    63  		ExtraConfig: []fstests.ExtraConfigItem{
    64  			{Name: name, Key: "type", Value: "crypt"},
    65  			{Name: name, Key: "remote", Value: tempdir},
    66  			{Name: name, Key: "password", Value: obscure.MustObscure("potato")},
    67  			{Name: name, Key: "filename_encryption", Value: "standard"},
    68  			{Name: name, Key: "filename_encoding", Value: "base64"},
    69  		},
    70  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
    71  		UnimplementableObjectMethods: []string{"MimeType"},
    72  		QuickTestOK:                  true,
    73  	})
    74  }
    75  
    76  func TestStandardBase32768(t *testing.T) {
    77  	if *fstest.RemoteName != "" {
    78  		t.Skip("Skipping as -remote set")
    79  	}
    80  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-standard")
    81  	name := "TestCrypt"
    82  	fstests.Run(t, &fstests.Opt{
    83  		RemoteName: name + ":",
    84  		NilObject:  (*crypt.Object)(nil),
    85  		ExtraConfig: []fstests.ExtraConfigItem{
    86  			{Name: name, Key: "type", Value: "crypt"},
    87  			{Name: name, Key: "remote", Value: tempdir},
    88  			{Name: name, Key: "password", Value: obscure.MustObscure("potato")},
    89  			{Name: name, Key: "filename_encryption", Value: "standard"},
    90  			{Name: name, Key: "filename_encoding", Value: "base32768"},
    91  		},
    92  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
    93  		UnimplementableObjectMethods: []string{"MimeType"},
    94  		QuickTestOK:                  true,
    95  	})
    96  }
    97  
    98  // TestOff runs integration tests against the remote
    99  func TestOff(t *testing.T) {
   100  	if *fstest.RemoteName != "" {
   101  		t.Skip("Skipping as -remote set")
   102  	}
   103  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-off")
   104  	name := "TestCrypt2"
   105  	fstests.Run(t, &fstests.Opt{
   106  		RemoteName: name + ":",
   107  		NilObject:  (*crypt.Object)(nil),
   108  		ExtraConfig: []fstests.ExtraConfigItem{
   109  			{Name: name, Key: "type", Value: "crypt"},
   110  			{Name: name, Key: "remote", Value: tempdir},
   111  			{Name: name, Key: "password", Value: obscure.MustObscure("potato2")},
   112  			{Name: name, Key: "filename_encryption", Value: "off"},
   113  		},
   114  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
   115  		UnimplementableObjectMethods: []string{"MimeType"},
   116  		QuickTestOK:                  true,
   117  	})
   118  }
   119  
   120  // TestObfuscate runs integration tests against the remote
   121  func TestObfuscate(t *testing.T) {
   122  	if *fstest.RemoteName != "" {
   123  		t.Skip("Skipping as -remote set")
   124  	}
   125  	if runtime.GOOS == "darwin" {
   126  		t.Skip("Skipping on macOS as obfuscating control characters makes filenames macOS can't cope with")
   127  	}
   128  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-obfuscate")
   129  	name := "TestCrypt3"
   130  	fstests.Run(t, &fstests.Opt{
   131  		RemoteName: name + ":",
   132  		NilObject:  (*crypt.Object)(nil),
   133  		ExtraConfig: []fstests.ExtraConfigItem{
   134  			{Name: name, Key: "type", Value: "crypt"},
   135  			{Name: name, Key: "remote", Value: tempdir},
   136  			{Name: name, Key: "password", Value: obscure.MustObscure("potato2")},
   137  			{Name: name, Key: "filename_encryption", Value: "obfuscate"},
   138  		},
   139  		SkipBadWindowsCharacters:     true,
   140  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
   141  		UnimplementableObjectMethods: []string{"MimeType"},
   142  		QuickTestOK:                  true,
   143  	})
   144  }
   145  
   146  // TestNoDataObfuscate runs integration tests against the remote
   147  func TestNoDataObfuscate(t *testing.T) {
   148  	if *fstest.RemoteName != "" {
   149  		t.Skip("Skipping as -remote set")
   150  	}
   151  	if runtime.GOOS == "darwin" {
   152  		t.Skip("Skipping on macOS as obfuscating control characters makes filenames macOS can't cope with")
   153  	}
   154  	tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-obfuscate")
   155  	name := "TestCrypt4"
   156  	fstests.Run(t, &fstests.Opt{
   157  		RemoteName: name + ":",
   158  		NilObject:  (*crypt.Object)(nil),
   159  		ExtraConfig: []fstests.ExtraConfigItem{
   160  			{Name: name, Key: "type", Value: "crypt"},
   161  			{Name: name, Key: "remote", Value: tempdir},
   162  			{Name: name, Key: "password", Value: obscure.MustObscure("potato2")},
   163  			{Name: name, Key: "filename_encryption", Value: "obfuscate"},
   164  			{Name: name, Key: "no_data_encryption", Value: "true"},
   165  		},
   166  		SkipBadWindowsCharacters:     true,
   167  		UnimplementableFsMethods:     []string{"OpenWriterAt", "OpenChunkWriter"},
   168  		UnimplementableObjectMethods: []string{"MimeType"},
   169  		QuickTestOK:                  true,
   170  	})
   171  }