Skip to content

Commit

Permalink
Revert "Check the onboarding payload code type in MTROnboardingPayloa…
Browse files Browse the repository at this point in the history
…dParser (project-chip#22024)" (project-chip#22026)

This reverts commit 2a5f7fe.
  • Loading branch information
woody-apple authored and isiu-apple committed Sep 16, 2022
1 parent 8616ba3 commit 82938e0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@
NSError * error;
MTRSetupPayload * payload;
MTROnboardingPayloadType codeType;
payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:codeString error:&error];
if (IsQRCode(codeString)) {
codeType = MTROnboardingPayloadTypeQRCode;
} else {
codeType = MTROnboardingPayloadTypeManualCode;
}
payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:codeString ofType:codeType error:&error];
if (error) {
LogNSError("Error: ", error);
return CHIP_ERROR_INTERNAL;
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/MTROnboardingPayloadParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef NS_ENUM(NSUInteger, MTROnboardingPayloadType) {
@interface MTROnboardingPayloadParser : NSObject

+ (nullable MTRSetupPayload *)setupPayloadForOnboardingPayload:(NSString *)onboardingPayload
ofType:(MTROnboardingPayloadType)type
error:(NSError * __autoreleasing *)error;

@end
Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/MTROnboardingPayloadParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
@implementation MTROnboardingPayloadParser

+ (nullable MTRSetupPayload *)setupPayloadForOnboardingPayload:(NSString *)onboardingPayload
ofType:(MTROnboardingPayloadType)type
error:(NSError * __autoreleasing *)error
{
MTRSetupPayload * payload;
// MTROnboardingPayloadTypeNFC is of type QR code and handled same as QR code
MTROnboardingPayloadType type
= isQRCode(onboardingPayload) ? MTROnboardingPayloadTypeQRCode : MTROnboardingPayloadTypeManualCode;
switch (type) {
case MTROnboardingPayloadTypeManualCode:
case MTROnboardingPayloadTypeAdmin:
payload = [self setupPayloadForManualCodeOnboardingPayload:onboardingPayload error:error];
break;
case MTROnboardingPayloadTypeQRCode:
case MTROnboardingPayloadTypeNFC:
payload = [self setupPayloadForQRCodeOnboardingPayload:onboardingPayload error:error];
break;
default:
Expand Down
71 changes: 70 additions & 1 deletion src/darwin/Framework/CHIPTests/MTRSetupPayloadParserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,40 @@ @implementation MTRSetupPayloadParserTests
- (void)testOnboardingPayloadParser_Manual_NoError
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"636108753500001000015" error:&error];
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"636108753500001000015"
ofType:MTROnboardingPayloadTypeManualCode
error:&error];

XCTAssertNotNil(payload);
XCTAssertNil(error);

XCTAssertTrue(payload.hasShortDiscriminator);
XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 10);
XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 123456780);
XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 1);
XCTAssertEqual(payload.productID.unsignedIntegerValue, 1);
XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowCustom);
XCTAssertEqual(payload.version.unsignedIntegerValue, 0);
XCTAssertNil(payload.rendezvousInformation);
}

- (void)testOnboardingPayloadParser_Manual_WrongType
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"636108753500001000015"
ofType:MTROnboardingPayloadTypeQRCode
error:&error];

XCTAssertNil(payload);
XCTAssertEqual(error.code, MTRErrorCodeInvalidArgument);
}

- (void)testOnboardingPayloadParser_Admin_NoError
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"636108753500001000015"
ofType:MTROnboardingPayloadTypeAdmin
error:&error];

XCTAssertNotNil(payload);
XCTAssertNil(error);
Expand All @@ -53,10 +86,22 @@ - (void)testOnboardingPayloadParser_Manual_NoError
XCTAssertNil(payload.rendezvousInformation);
}

- (void)testOnboardingPayloadParser_Admin_WrongType
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"636108753500001000015"
ofType:MTROnboardingPayloadTypeQRCode
error:&error];

XCTAssertNil(payload);
XCTAssertEqual(error.code, MTRErrorCodeInvalidArgument);
}

- (void)testOnboardingPayloadParser_QRCode_NoError
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"MT:R5L90MP500K64J00000"
ofType:MTROnboardingPayloadTypeQRCode
error:&error];

XCTAssertNotNil(payload);
Expand All @@ -73,11 +118,23 @@ - (void)testOnboardingPayloadParser_QRCode_NoError
XCTAssertEqual([payload.rendezvousInformation unsignedLongValue], MTRDiscoveryCapabilitiesSoftAP);
}

- (void)testOnboardingPayloadParser_QRCode_WrongType
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"MT:R5L90MP500K64J00000"
ofType:MTROnboardingPayloadTypeAdmin
error:&error];

XCTAssertNil(payload);
XCTAssertEqual(error.code, MTRErrorCodeIntegrityCheckFailed);
}

- (void)testOnboardingPayloadParser_NFC_NoError
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser
setupPayloadForOnboardingPayload:@"MT:R5L90MP500K64J0A33P0SET70.QT52B.E23-WZE0WISA0DK5N1K8SQ1RYCU1O0"
ofType:MTROnboardingPayloadTypeNFC
error:&error];

XCTAssertNotNil(payload);
Expand All @@ -94,6 +151,18 @@ - (void)testOnboardingPayloadParser_NFC_NoError
XCTAssertEqual([payload.rendezvousInformation unsignedLongValue], MTRDiscoveryCapabilitiesSoftAP);
}

- (void)testOnboardingPayloadParser_NFC_WrongType
{
NSError * error;
MTRSetupPayload * payload = [MTROnboardingPayloadParser
setupPayloadForOnboardingPayload:@"MT:R5L90MP500K64J0A33P0SET70.QT52B.E23-WZE0WISA0DK5N1K8SQ1RYCU1O0"
ofType:MTROnboardingPayloadTypeManualCode
error:&error];

XCTAssertNil(payload);
XCTAssertEqual(error.code, MTRErrorCodeIntegrityCheckFailed);
}

- (void)testManualParser
{
NSError * error;
Expand Down

0 comments on commit 82938e0

Please sign in to comment.