Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EUI ordering in claiming #6336

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/deviceclaimingserver/grpc_end_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (edcs *endDeviceClaimingServer) Claim(
return nil, errClaimingNotSupported.WithAttributes("eui", joinEUI)
}

err := claimer.Claim(ctx, devEUI, joinEUI, claimAuthenticationCode)
err := claimer.Claim(ctx, joinEUI, devEUI, claimAuthenticationCode)
if err != nil {
return nil, err
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/deviceclaimingserver/grpc_end_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
registeredJoinEUI = types.EUI64{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C}
unRegisteredJoinEUI = types.EUI64{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D}
registeredDevEUI = types.EUI64{0x00, 0x04, 0xA3, 0x0B, 0x00, 0x1C, 0x05, 0x30}
authenticationCode = "BEEF1234"
)

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
Expand Down Expand Up @@ -88,6 +89,14 @@ func TestEndDeviceClaimingServer(t *testing.T) {
enddevices.Config{},
enddevices.WithClaimer("test", &MockClaimer{
JoinEUI: registeredJoinEUI,
ClaimFunc: func(
ctx context.Context, joinEUI, devEUI types.EUI64, claimAuthenticationCode string,
) error {
a.So(joinEUI, should.Equal, registeredJoinEUI)
a.So(devEUI, should.Resemble, registeredDevEUI)
a.So(claimAuthenticationCode, should.Equal, authenticationCode)
return nil
},
}),
)
a.So(err, should.BeNil)
Expand Down Expand Up @@ -205,7 +214,7 @@ func TestEndDeviceClaimingServer(t *testing.T) {
AuthenticatedIdentifiers: &ttnpb.ClaimEndDeviceRequest_AuthenticatedIdentifiers{
JoinEui: registeredJoinEUI.Bytes(),
DevEui: registeredDevEUI.Bytes(),
AuthenticationCode: "TEST1234",
AuthenticationCode: authenticationCode,
},
},
TargetApplicationIds: registeredApplicationIDs,
Expand All @@ -223,7 +232,7 @@ func TestEndDeviceClaimingServer(t *testing.T) {
AuthenticatedIdentifiers: &ttnpb.ClaimEndDeviceRequest_AuthenticatedIdentifiers{
JoinEui: registeredJoinEUI.Bytes(),
DevEui: registeredDevEUI.Bytes(),
AuthenticationCode: "TEST1234",
AuthenticationCode: authenticationCode,
},
},
TargetApplicationIds: registeredApplicationIDs,
Expand Down
7 changes: 5 additions & 2 deletions pkg/deviceclaimingserver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
// MockClaimer is a mock Claimer.
type MockClaimer struct {
JoinEUI types.EUI64

ClaimFunc func(context.Context, types.EUI64, types.EUI64, string) error
}

// SupportsJoinEUI returns whether the Join Server supports this JoinEUI.
Expand All @@ -32,9 +34,10 @@ func (m MockClaimer) SupportsJoinEUI(joinEUI types.EUI64) bool {
}

// Claim claims an End Device.
func (MockClaimer) Claim(_ context.Context, _, _ types.EUI64, _ string,
func (m MockClaimer) Claim(
ctx context.Context, joinEUI, devEUI types.EUI64, claimAuthenticationCode string,
) error {
return nil
return m.ClaimFunc(ctx, joinEUI, devEUI, claimAuthenticationCode)
}

// GetClaimStatus returns the claim status an End Device.
Expand Down