(t *testing.T)
| 167 | } |
| 168 | |
| 169 | func TestEnDecryptFileInfo(t *testing.T) { |
| 170 | if cryptoIsBrokenUnderRaceDetector { |
| 171 | t.Skip("cannot test") |
| 172 | } |
| 173 | |
| 174 | var key [32]byte |
| 175 | fi := encFileInfo() |
| 176 | |
| 177 | enc := encryptFileInfo(testKeyGen, fi, &key) |
| 178 | if bytes.Equal(enc.Blocks[0].Hash, enc.Blocks[1].Hash) { |
| 179 | t.Error("block hashes should not repeat when on different offsets") |
| 180 | } |
| 181 | if enc.RawBlockSize < MinBlockSize { |
| 182 | t.Error("Too small raw block size:", enc.RawBlockSize) |
| 183 | } |
| 184 | if enc.Sequence != fi.Sequence { |
| 185 | t.Error("encrypted fileinfo didn't maintain sequence number") |
| 186 | } |
| 187 | again := encryptFileInfo(testKeyGen, fi, &key) |
| 188 | if !bytes.Equal(enc.Blocks[0].Hash, again.Blocks[0].Hash) { |
| 189 | t.Error("block hashes should remain stable (0)") |
| 190 | } |
| 191 | if !bytes.Equal(enc.Blocks[1].Hash, again.Blocks[1].Hash) { |
| 192 | t.Error("block hashes should remain stable (1)") |
| 193 | } |
| 194 | |
| 195 | // Simulate the remote setting the sequence number when writing to db |
| 196 | enc.Sequence = 10 |
| 197 | |
| 198 | dec, err := DecryptFileInfo(testKeyGen, enc, &key) |
| 199 | if err != nil { |
| 200 | t.Error(err) |
| 201 | } |
| 202 | if dec.Sequence != enc.Sequence { |
| 203 | t.Error("decrypted fileinfo didn't maintain sequence number") |
| 204 | } |
| 205 | dec.Sequence = fi.Sequence |
| 206 | if !reflect.DeepEqual(fi, dec) { |
| 207 | t.Error("mismatch after decryption") |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | func TestEncryptedFileInfoConsistency(t *testing.T) { |
| 212 | if cryptoIsBrokenUnderRaceDetector { |
nothing calls this directly
no test coverage detected