Skip to content

Commit

Permalink
added blinded creds to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
clD11 authored and Sneagan committed Aug 11, 2022
1 parent 4bdeae7 commit e86b39c
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 77 deletions.
116 changes: 79 additions & 37 deletions avro/generated/signing_result_v2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions avro/generated/signing_result_v2_set.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions avro/schemas/signing_result_v2.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
},
{"name": "public_key", "type": "string"},
{"name": "proof", "type": "string"},
{"name": "valid_from", "type": ["null", "string"], "default": null},
{"name": "valid_to", "type": ["null", "string"], "default": null},
{"name": "status", "type": {
"name": "SigningResultV2Status",
"type": "enum",
"symbols": ["ok", "invalid_issuer", "error"]
}},
{"name": "associated_data", "type": "bytes", "doc": "contains METADATA"}
{"name": "associated_data", "type": "bytes", "doc": "contains METADATA"},
{"name": "valid_to", "type": ["null", "string"], "default": null},
{"name": "valid_from", "type": ["null", "string"], "default": null},
{
"name": "blinded_tokens",
"type": {"type" : "array", "items": {"type": "string"}},
"default": []
}
]
}
}
Expand Down
79 changes: 58 additions & 21 deletions kafka/avro_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,64 @@
package kafka

//func TestOriginalAvroNewSchema(t *testing.T) {
//
// buf := bytes.NewBuffer([]byte{})
//
// orig := &avroSchema.SigningResultV1{
// Signed_tokens: []string{"signed token"},
// Issuer_public_key: "issuer public key",
// Proof: "proof",
import (
"bytes"
avroSchema "github.com/brave-intl/challenge-bypass-server/avro/generated"
"github.com/brave-intl/challenge-bypass-server/utils/test"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

// Tests v2 adds new fields validTo, validFrom and BlindedTokens.
func TestSchemaCompatability_SigningResult_V2ToV1(t *testing.T) {
v2 := &avroSchema.SigningResultV2{
Signed_tokens: []string{test.RandomString()},
Issuer_public_key: test.RandomString(),
Proof: test.RandomString(),
Valid_from: &avroSchema.UnionNullString{String: time.Now().String(),
UnionType: avroSchema.UnionNullStringTypeEnumString},
Valid_to: &avroSchema.UnionNullString{String: time.Now().String(),
UnionType: avroSchema.UnionNullStringTypeEnumString},
Status: 1,
Associated_data: []byte{},
Blinded_tokens: []string{test.RandomString()},
}

var buf bytes.Buffer
err := v2.Serialize(&buf)
assert.NoError(t, err)

v1, err := avroSchema.DeserializeSigningResultV1(&buf)
assert.NoError(t, err)

assert.Equal(t, v2.Signed_tokens, v1.Signed_tokens)
assert.Equal(t, v2.Issuer_public_key, v1.Issuer_public_key)
assert.Equal(t, v2.Proof, v1.Proof)
assert.Equal(t, v2.Status.String(), v1.Status.String())
}

//// Tests v2 consumers reading v1 messages.
//func TestSchemaCompatability_SigningResult_V1ToV2(t *testing.T) {
// v1 := &avroSchema.SigningResultV1{
// Signed_tokens: []string{test.RandomString()},
// Issuer_public_key: test.RandomString(),
// Proof: test.RandomString(),
// Status: 0,
// Associated_data: []byte{},
// }
//
// if err := orig.Serialize(buf); err != nil {
// t.Error("failed to serialize original message type: ", err)
// return
// }
// var buf bytes.Buffer
// err := v1.Serialize(&buf)
// assert.NoError(t, err)
//
// newSigningResult, err := avroSchema.DeserializeSigningResultV2(buf)
// if err != nil {
// t.Error("failed to deserialize into new message type: ", err)
// return
// }
// if newSigningResult.Proof != "proof" {
// t.Error("invalid attribute in signing result: ", newSigningResult.Proof)
// return
// }
// v2, err := avroSchema.DeserializeSigningResultV2(&buf)
// assert.NoError(t, err)
//
// assert.Equal(t, v1.Signed_tokens, v2.Signed_tokens)
// assert.Equal(t, v1.Issuer_public_key, v2.Issuer_public_key)
// assert.Equal(t, v1.Proof, v2.Proof)
// assert.Equal(t, v1.Status.String(), v2.Status.String())
// //assert.Nil(t, v2.Valid_to)
// //assert.Nil(t, v2.Valid_from)
// assert.Empty(t, v2.Blinded_tokens)
//}
Loading

0 comments on commit e86b39c

Please sign in to comment.