From f28d85fad599ffaef9a8e1f353911c81a6605d2f Mon Sep 17 00:00:00 2001
From: Jakob Unterwurzacher
Date: Sun, 1 Apr 2018 21:23:32 +0200
Subject: fsck: add initial implementation

Most corruption cases except xattr should be covered.
With test filesystem.

The output is still pretty ugly. xattr support will
be added in the next commits.
---
 tests/fsck/broken_fs_v1.4/GUvJFSfy7S1AXUdy4pDRLw   |   1 +
 .../K2m0E6qzIfoLkVZJanoUiQ/mWEr9JLch2FW40qhbnPgpg  |   0
 tests/fsck/broken_fs_v1.4/OtrNpznB8aMTKPi6bopM2g   | Bin 0 -> 63 bytes
 .../PnkpLqHimGudw4C3jFY-Yw/_y58usbKXq_YRPMKfC3TNw  |   0
 .../PnkpLqHimGudw4C3jFY-Yw/gocryptfs.diriv         |   2 ++
 tests/fsck/broken_fs_v1.4/gocryptfs.conf           |  20 ++++++++++++++++
 tests/fsck/broken_fs_v1.4/gocryptfs.diriv          |   2 ++
 tests/fsck/broken_fs_v1.4/invalid_file_name.3      |   0
 tests/fsck/broken_fs_v1.4/invalid_file_name_2      |   0
 tests/fsck/broken_fs_v1.4/invalid_file_name____1   |   0
 tests/fsck/broken_fs_v1.4/qOA8a4yuvgbMFpz7277R8A   |   1 +
 tests/fsck/broken_fs_v1.4/s-P7PcQDUcVkoeMDnC3EYA   |   1 +
 tests/fsck/broken_fs_v1.4/vDKs8a7UtM3PmEKk9wlPcA   | Bin 0 -> 77 bytes
 tests/fsck/fsck_test.go                            |  26 +++++++++++++++++++++
 tests/fsck/run_fsck.bash                           |   2 ++
 15 files changed, 55 insertions(+)
 create mode 120000 tests/fsck/broken_fs_v1.4/GUvJFSfy7S1AXUdy4pDRLw
 create mode 100644 tests/fsck/broken_fs_v1.4/K2m0E6qzIfoLkVZJanoUiQ/mWEr9JLch2FW40qhbnPgpg
 create mode 100644 tests/fsck/broken_fs_v1.4/OtrNpznB8aMTKPi6bopM2g
 create mode 100644 tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/_y58usbKXq_YRPMKfC3TNw
 create mode 100644 tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/gocryptfs.diriv
 create mode 100644 tests/fsck/broken_fs_v1.4/gocryptfs.conf
 create mode 100644 tests/fsck/broken_fs_v1.4/gocryptfs.diriv
 create mode 100644 tests/fsck/broken_fs_v1.4/invalid_file_name.3
 create mode 100644 tests/fsck/broken_fs_v1.4/invalid_file_name_2
 create mode 100644 tests/fsck/broken_fs_v1.4/invalid_file_name____1
 create mode 100644 tests/fsck/broken_fs_v1.4/qOA8a4yuvgbMFpz7277R8A
 create mode 120000 tests/fsck/broken_fs_v1.4/s-P7PcQDUcVkoeMDnC3EYA
 create mode 100644 tests/fsck/broken_fs_v1.4/vDKs8a7UtM3PmEKk9wlPcA
 create mode 100644 tests/fsck/fsck_test.go
 create mode 100755 tests/fsck/run_fsck.bash

(limited to 'tests/fsck')

diff --git a/tests/fsck/broken_fs_v1.4/GUvJFSfy7S1AXUdy4pDRLw b/tests/fsck/broken_fs_v1.4/GUvJFSfy7S1AXUdy4pDRLw
new file mode 120000
index 0000000..7bbd005
--- /dev/null
+++ b/tests/fsck/broken_fs_v1.4/GUvJFSfy7S1AXUdy4pDRLw
@@ -0,0 +1 @@
+RFPnVN8r1HjIrFVJ8PffC7ObzAIeBx3DQh8FbgvmbT8Ho8mU
\ No newline at end of file
diff --git a/tests/fsck/broken_fs_v1.4/K2m0E6qzIfoLkVZJanoUiQ/mWEr9JLch2FW40qhbnPgpg b/tests/fsck/broken_fs_v1.4/K2m0E6qzIfoLkVZJanoUiQ/mWEr9JLch2FW40qhbnPgpg
new file mode 100644
index 0000000..e69de29
diff --git a/tests/fsck/broken_fs_v1.4/OtrNpznB8aMTKPi6bopM2g b/tests/fsck/broken_fs_v1.4/OtrNpznB8aMTKPi6bopM2g
new file mode 100644
index 0000000..dab7c69
Binary files /dev/null and b/tests/fsck/broken_fs_v1.4/OtrNpznB8aMTKPi6bopM2g differ
diff --git a/tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/_y58usbKXq_YRPMKfC3TNw b/tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/_y58usbKXq_YRPMKfC3TNw
new file mode 100644
index 0000000..e69de29
diff --git a/tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/gocryptfs.diriv b/tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/gocryptfs.diriv
new file mode 100644
index 0000000..178763a
--- /dev/null
+++ b/tests/fsck/broken_fs_v1.4/PnkpLqHimGudw4C3jFY-Yw/gocryptfs.diriv
@@ -0,0 +1,2 @@
+f�`��
+{g*@w�6�
\ No newline at end of file
diff --git a/tests/fsck/broken_fs_v1.4/gocryptfs.conf b/tests/fsck/broken_fs_v1.4/gocryptfs.conf
new file mode 100644
index 0000000..cedf571
--- /dev/null
+++ b/tests/fsck/broken_fs_v1.4/gocryptfs.conf
@@ -0,0 +1,20 @@
+{
+	"Creator": "gocryptfs v1.4.4-13-ga4f3a7d-dirty",
+	"EncryptedKey": "yfnIx9uKv2ZX80KXOlfb4fWws3RNqvcjsx/Ajr0x4pRfg8NLqhWRpEUWGk8NSdVFXKWVDgdhSoYkbfVnFXl07g==",
+	"ScryptObject": {
+		"Salt": "R78m123zJxxO6uU1bg6/0azppry1FoGdH1/Op1xFq+4=",
+		"N": 65536,
+		"R": 8,
+		"P": 1,
+		"KeyLen": 32
+	},
+	"Version": 2,
+	"FeatureFlags": [
+		"GCMIV128",
+		"HKDF",
+		"DirIV",
+		"EMENames",
+		"LongNames",
+		"Raw64"
+	]
+}
diff --git a/tests/fsck/broken_fs_v1.4/gocryptfs.diriv b/tests/fsck/broken_fs_v1.4/gocryptfs.diriv
new file mode 100644
index 0000000..d7bbcda
--- /dev/null
+++ b/tests/fsck/broken_fs_v1.4/gocryptfs.diriv
@@ -0,0 +1,2 @@
+�8]�jM
+�Pg��D��
\ No newline at end of file
diff --git a/tests/fsck/broken_fs_v1.4/invalid_file_name.3 b/tests/fsck/broken_fs_v1.4/invalid_file_name.3
new file mode 100644
index 0000000..e69de29
diff --git a/tests/fsck/broken_fs_v1.4/invalid_file_name_2 b/tests/fsck/broken_fs_v1.4/invalid_file_name_2
new file mode 100644
index 0000000..e69de29
diff --git a/tests/fsck/broken_fs_v1.4/invalid_file_name____1 b/tests/fsck/broken_fs_v1.4/invalid_file_name____1
new file mode 100644
index 0000000..e69de29
diff --git a/tests/fsck/broken_fs_v1.4/qOA8a4yuvgbMFpz7277R8A b/tests/fsck/broken_fs_v1.4/qOA8a4yuvgbMFpz7277R8A
new file mode 100644
index 0000000..8621a03
--- /dev/null
+++ b/tests/fsck/broken_fs_v1.4/qOA8a4yuvgbMFpz7277R8A
@@ -0,0 +1 @@
+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
diff --git a/tests/fsck/broken_fs_v1.4/s-P7PcQDUcVkoeMDnC3EYA b/tests/fsck/broken_fs_v1.4/s-P7PcQDUcVkoeMDnC3EYA
new file mode 120000
index 0000000..158f38a
--- /dev/null
+++ b/tests/fsck/broken_fs_v1.4/s-P7PcQDUcVkoeMDnC3EYA
@@ -0,0 +1 @@
+Qso5-4WJ2iAxF674mUarvuNbIMTLSJLqfEh3Chq3I_Rm2sY2
\ No newline at end of file
diff --git a/tests/fsck/broken_fs_v1.4/vDKs8a7UtM3PmEKk9wlPcA b/tests/fsck/broken_fs_v1.4/vDKs8a7UtM3PmEKk9wlPcA
new file mode 100644
index 0000000..1dff1a1
Binary files /dev/null and b/tests/fsck/broken_fs_v1.4/vDKs8a7UtM3PmEKk9wlPcA differ
diff --git a/tests/fsck/fsck_test.go b/tests/fsck/fsck_test.go
new file mode 100644
index 0000000..7506636
--- /dev/null
+++ b/tests/fsck/fsck_test.go
@@ -0,0 +1,26 @@
+package fsck
+
+import (
+	"os/exec"
+	"strings"
+	"testing"
+
+	"github.com/rfjakob/gocryptfs/internal/exitcodes"
+	"github.com/rfjakob/gocryptfs/tests/test_helpers"
+)
+
+func TestBrokenFsV14(t *testing.T) {
+	cmd := exec.Command(test_helpers.GocryptfsBinary, "-fsck", "-extpass", "echo test", "broken_fs_v1.4")
+	outBin, err := cmd.CombinedOutput()
+	out := string(outBin)
+	t.Log(out)
+	code := test_helpers.ExtractCmdExitCode(err)
+	if code != exitcodes.FsckErrors {
+		t.Errorf("wrong exit code, have=%d want=%d", code, exitcodes.FsckErrors)
+	}
+	lines := strings.Split(out, "\n")
+	summaryLine := lines[len(lines)-2]
+	if summaryLine != "fsck: found 5 problems" {
+		t.Errorf("wrong summary line: %q", summaryLine)
+	}
+}
diff --git a/tests/fsck/run_fsck.bash b/tests/fsck/run_fsck.bash
new file mode 100755
index 0000000..9637381
--- /dev/null
+++ b/tests/fsck/run_fsck.bash
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec ../../gocryptfs -fsck -extpass "echo test" broken_fs_v1.4
-- 
cgit v1.2.3