Esempio n. 1
0
		Describe("unkown encoding", func() {
			It("fails with an unknown encoding error", func() {
				payload := []byte("some-payload")
				_, err := encoder.Encode(format.Encoding([2]byte{'9', '9'}), payload)

				Expect(err).To(HaveOccurred())
			})
		})
	})

	Describe("Decode", func() {
		Describe("LEGACY_UNENCODED", func() {
			It("returns the payload back", func() {
				payload := []byte("some-payload")
				decoded, err := encoder.Decode(payload)

				Expect(err).NotTo(HaveOccurred())
				Expect(decoded).To(Equal(payload))
			})
		})

		Describe("UNENCODED", func() {
			It("returns the payload back without an encoding type prefix", func() {
				payload := []byte("some-payload")
				decoded, err := encoder.Decode(append([]byte("00"), payload...))

				Expect(err).NotTo(HaveOccurred())
				Expect(decoded).To(Equal(payload))
			})
		})
Esempio n. 2
0
			Expect(err).NotTo(HaveOccurred())
			_, err = storeClient.Set(fmt.Sprintf("%s/my/nested/key-2", etcd.V1SchemaRoot), encoded2, etcd.NO_TTL)
			Expect(err).NotTo(HaveOccurred())

			cryptor = makeCryptor("new", "old")

			etcdDB = etcd.NewETCD(format.ENCRYPTED_PROTO, 100, 100, DesiredLRPCreationTimeout, cryptor, storeClient, clock)
			err = etcdDB.PerformEncryption(logger)
			Expect(err).NotTo(HaveOccurred())

			cryptor = makeCryptor("new")
			encoder = format.NewEncoder(cryptor)

			res, err := storeClient.Get(fmt.Sprintf("%s/my/key-1", etcd.V1SchemaRoot), false, false)
			Expect(err).NotTo(HaveOccurred())
			decrypted1, err := encoder.Decode([]byte(res.Node.Value))
			Expect(err).NotTo(HaveOccurred())
			Expect(decrypted1).To(Equal(value1))

			res, err = storeClient.Get(fmt.Sprintf("%s/my/nested/key-2", etcd.V1SchemaRoot), false, false)
			Expect(err).NotTo(HaveOccurred())
			decrypted2, err := encoder.Decode([]byte(res.Node.Value))
			Expect(err).NotTo(HaveOccurred())
			Expect(decrypted2).To(Equal(value2))
		})

		It("does not fail encryption if it can't read a record", func() {
			var cryptor encryption.Cryptor
			var encoder format.Encoder

			value1 := []byte("some text")
Esempio n. 3
0
			sqlDB := sqldb.NewSQLDB(db, 5, 5, format.ENCRYPTED_PROTO, cryptor, fakeGUIDProvider, fakeClock, dbFlavor)
			err = sqlDB.PerformEncryption(logger)
			Expect(err).NotTo(HaveOccurred())

			cryptor = makeCryptor("new")
			encoder = format.NewEncoder(cryptor)

			var result []byte
			queryStr = "SELECT task_definition FROM tasks WHERE guid = ?"
			if test_helpers.UsePostgres() {
				queryStr = test_helpers.ReplaceQuestionMarks(queryStr)
			}
			row := db.QueryRow(queryStr, taskGuid)
			err = row.Scan(&result)
			Expect(err).NotTo(HaveOccurred())
			decrypted1, err := encoder.Decode(result)
			Expect(err).NotTo(HaveOccurred())
			Expect(decrypted1).To(Equal(value1))

			var runInfo, volumePlacement []byte
			queryStr = "SELECT run_info, volume_placement FROM desired_lrps WHERE process_guid = ?"
			if test_helpers.UsePostgres() {
				queryStr = test_helpers.ReplaceQuestionMarks(queryStr)
			}
			row = db.QueryRow(queryStr, processGuid)
			err = row.Scan(&runInfo, &volumePlacement)
			Expect(err).NotTo(HaveOccurred())
			decrypted2, err := encoder.Decode(runInfo)
			Expect(err).NotTo(HaveOccurred())
			decrypted3, err := encoder.Decode(volumePlacement)
			Expect(err).NotTo(HaveOccurred())