package decrypt

import (
	"fmt"
	"testing"

	"github.com/project-flogo/core/activity"
	"github.com/project-flogo/core/support/test"
	"github.com/stretchr/testify/assert"
)

const plaintext = `This is my message`

const ciphertext = `
-----BEGIN PGP MESSAGE-----

wYwD6bYhtpRVcqQBBACeYy5J8/F7nIdJNLaPXnoXdg1tpGE3yKJoHyq4B0z0wh2L
ZdVPgdMJ1+998H5vrBJk/ybFsFVIE26D2qAXQbviIKGMIDvW5Uu/ahjh/aSJLV56
jYiJTZUwE0GweTBQ3YYYsaOSQgJWecfAsf8ChkwBvLRbxqFsKlwNvBiv8enp69JD
Acvzw1TA1ct6Td6WWoIGz1Pv3CI/mhGSmfo1KrPV2XB1ayzYMOR8L7ExuHb6fqhw
LXXy3JsYO1F6fLbrvq2gReQAWQ==
=TUbm
-----END PGP MESSAGE-----`

const pubKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: Keybase OpenPGP v2.1.17
Comment: https://keybase.io/crypto

xo0EabgxNAEEALow5SvP3WpF9zb3nJrFhbf5POJ9Kpl8sYOa+BbWL2Bdye2oX1rn
Slvyauo9lOH5w9MSmZT/vSGqOhgGNs9lYbIh87nZTuZ5chHPTUSJSZS/6ynaIhSB
binbv2cgY1n26KvXsQ67fMNjfzHHKb39uA+IMqNIiDRlSQ/k7lDOikH7ABEBAAHN
GSA8bWFyay5tdXNzZXR0QHRpYmNvLmNvbT7CtAQTAQoAHgUCabgxNAIbLwMLCQcD
FQoIAh4BAheAAxYCAQIZAQAKCRAllQQUorcVEg4+A/96kCzHukDO8VCvylzS7FLB
coj58eHRUdhrOo/NDgNwcxoyUXFi7HyozjF5iP5hbiGK67C18wTz2UTDUph5OUrW
cmDpsx5vzxTkSPWIJZUoBkedOEggf8GJcnWreaWw5atuqDY+wrQVJRU23qQ/VrO/
XDCG6T6kR01W6dL2RhTHXc6NBGm4MTQBBAC+9FMIGObejwZY1HK4FWJs7Hc0zLwi
eWR9p00D2bnzal2U7U0AGfFcoReM/Zc5w3K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
b9nqXdu8hrp8DXn+RAaQ26b0ahWKVDGCHykJlb2uV00yFENxOELyD1Jaj+b24Q4T
lc22RU4vFCjbFbi5D/pD5l6B2U9JC9WnmcrnJrzVXdTr+68iRaV+06tb
=K9s3
-----END PGP PUBLIC KEY BLOCK-----`

const privKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: Keybase OpenPGP v2.1.17
Comment: https://keybase.io/crypto

xcEYBGm4MTQBBAC6MOUrz91qRfc295yaxYW3+TzifSqZfLGDmvgW1i9gXcntqF9a
50pb8mrqPZTh+cPTEpmU/70hqjoYBjbPZWGyIfO52U7meXIRz01EiUmUv+sp2iIU
gW4p279nIGNZ9uir17EOu3zDY38xxym9/bgPiDKjSIg0ZUkP5O5QzopB+wARAQAB
AAP8Cn1Ns+xX2NsMjz608RfsAs4vqsI1dQSMNadfObN4Y3v1L9vv/1LkzWL4uK3z
0M/9mHXFoZokzBw8ffT/qoCCLT+xjq3wkoTJiHqClZ5K5EchmetSJuIAQ4kU/MuE
/CBDk5TE+weFlqa2hhWucORgr3XFHITvNyR5/Et2ppmlG+0CAPQCfIMNZaXqhVQc
WZXPZb9KD619TlAESxC48aIEdx/J4eE7BFr2889wFsAZGrVyq4Nn8t9QoOHzrR/Z
VljZ/OcCAMNXFHDCacsaAKmGuUTRuhmz4JK5cf86LRh7xbztTb04hfdkkfyLKSyY
+47VqZfIUeD/dPPEzuuv1sLMMbwSu80CAITHQA0+kLtz4eMYUYLf1jYtQ89Xt3ar
vTckxO+wrwV1i9uFSRcAqxoMA1F5yC4R16d+vHPXeIh80ACnmn7EiDysIM0ZIDxt
YXJrLm11c3NldHRAdGliY28uY29tPsK0BBMBCgAeBQJpuDE0AhsvAwsJBwMVCggC
HgECF4ADFgIBAhkBAAoJECWVBBSitxUSDj4D/3qQLMe6QM7xUK/KXNLsUsFyiPnx
4dFR2Gs6j80OA3BzGjJRcWLsfKjOMXmI/mFuIYrrsLXzBPPZRMNSmHk5StZyYOmz
Hm/P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ykJlb2uV00yFENxOELyD1Jaj+b24Q4Tlc22RU4vFCjbFbi5
D/pD5l6B2U9JC9WnmcrnJrzVXdTr+68iRaV+06tb
=5aKj
-----END PGP PRIVATE KEY BLOCK-----`

func TestRegister(t *testing.T) {

	ref := activity.GetRef(&MyActivity{})
	act := activity.Get(ref)

	assert.NotNil(t, act)
}

func TestEval(t *testing.T) {

	t.Helper()

	act := &MyActivity{}

	tc := test.NewActivityContext(act.Metadata())

	tc.SetInput("ciphertext", ciphertext)
	tc.SetInput("privatekey", privKeyArmored)

	done, err := act.Eval(tc)
	if !done {
		t.Fatal(err)
	}

	assert.True(t, done)
	var output = fmt.Sprint(tc.GetOutput("plaintext"))
	fmt.Println("Output    : ", string(output))

	assert.Equal(t,plaintext,output)
}
