handleKeyRegistryTest runs a test suite on reg.
(t *testing.T, reg KeyRegistry)
| 358 | |
| 359 | // handleKeyRegistryTest runs a test suite on reg. |
| 360 | func handleKeyRegistryTest(t *testing.T, reg KeyRegistry) { |
| 361 | a := assertions.New(t) |
| 362 | |
| 363 | ctx := test.Context() |
| 364 | |
| 365 | joinEUI := types.EUI64{0x42, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
| 366 | devEUI := types.EUI64{0x42, 0x42, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
| 367 | pb := &ttnpb.SessionKeys{ |
| 368 | SessionKeyId: []byte{0x11, 0x22, 0x33, 0x44}, |
| 369 | FNwkSIntKey: test.DefaultFNwkSIntKeyEnvelope, |
| 370 | SNwkSIntKey: test.DefaultSNwkSIntKeyEnvelope, |
| 371 | NwkSEncKey: test.DefaultNwkSEncKeyEnvelope, |
| 372 | AppSKey: test.DefaultAppSKeyEnvelope, |
| 373 | } |
| 374 | |
| 375 | ret, err := reg.GetByID(ctx, joinEUI, devEUI, pb.SessionKeyId, ttnpb.SessionKeysFieldPathsTopLevel) |
| 376 | if !a.So(err, should.NotBeNil) || !a.So(errors.IsNotFound(err), should.BeTrue) { |
| 377 | t.Fatalf("Error received: %v", err) |
| 378 | } |
| 379 | a.So(ret, should.BeNil) |
| 380 | |
| 381 | ret, err = reg.SetByID(ctx, joinEUI, devEUI, pb.SessionKeyId, |
| 382 | []string{ |
| 383 | "app_s_key", |
| 384 | "f_nwk_s_int_key", |
| 385 | "nwk_s_enc_key", |
| 386 | "s_nwk_s_int_key", |
| 387 | }, |
| 388 | func(stored *ttnpb.SessionKeys) (*ttnpb.SessionKeys, []string, error) { |
| 389 | if !a.So(stored, should.BeNil) { |
| 390 | t.Fatal("Registry is not empty") |
| 391 | } |
| 392 | return ttnpb.Clone(pb), []string{ |
| 393 | "app_s_key", |
| 394 | "f_nwk_s_int_key", |
| 395 | "nwk_s_enc_key", |
| 396 | "s_nwk_s_int_key", |
| 397 | "session_key_id", |
| 398 | }, nil |
| 399 | }, |
| 400 | ) |
| 401 | if !a.So(err, should.BeNil) || !a.So(ret, should.NotBeNil) { |
| 402 | t.Fatalf("Failed to create keys: %s", err) |
| 403 | } |
| 404 | a.So(ret, should.Resemble, pb) |
| 405 | |
| 406 | ret, err = reg.GetByID(ctx, joinEUI, devEUI, pb.SessionKeyId, ttnpb.SessionKeysFieldPathsTopLevel) |
| 407 | a.So(err, should.BeNil) |
| 408 | a.So(ret, should.HaveEmptyDiff, pb) |
| 409 | |
| 410 | pbOther := ttnpb.Clone(pb) |
| 411 | joinEUIOther := types.EUI64{0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
| 412 | devEUIOther := types.EUI64{0x43, 0x42, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
| 413 | |
| 414 | ret, err = reg.GetByID(ctx, joinEUIOther, devEUIOther, pbOther.SessionKeyId, ttnpb.SessionKeysFieldPathsTopLevel) |
| 415 | if !a.So(err, should.NotBeNil) || !a.So(errors.IsNotFound(err), should.BeTrue) { |
| 416 | t.Fatalf("Error received: %v", err) |
| 417 | } |
no test coverage detected