465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * The contents of this file are subject to the terms of the Common Development and
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * Distribution License (the License). You may not use this file except in compliance with the
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * specific language governing permission and limitations under the License.
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * When distributing Covered Software, include this CDDL Header Notice in each file and include
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * Header, with the fields enclosed by brackets [] replaced by your own identifying
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * information: "Portions copyright [year] [name of copyright owner]".
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * Copyright 2016 ForgeRock AS.
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell#import "FRAQRUtils.h"
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell- (void)testReplaceCharactersForURLDecodingReplacesDashes {
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *result = [FRAQRUtils replaceCharactersForURLDecoding:content];
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell XCTAssertEqualObjects(result, @"+123+456+");
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell- (void)testReplaceCharactersForURLDecodingReplacesUnderscores {
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *result = [FRAQRUtils replaceCharactersForURLDecoding:content];
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell XCTAssertEqualObjects(result, @"/123/456/");
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell- (void)testReplaceCharactersForURLDecodingDoesntReplaceIfValid {
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *result = [FRAQRUtils replaceCharactersForURLDecoding:content];
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni NSData *result = [FRAQRUtils decodeBase64:nil];
2708b42676edf3d2e8f85b3c22b9e3be3cf43eb8Diego Colantoni- (void)testIsBase64ReturnsTrueIfStringIsValidBase64 {
2708b42676edf3d2e8f85b3c22b9e3be3cf43eb8Diego Colantoni BOOL result = [FRAQRUtils isBase64:@"somethingTHATisvalid1244+"];
2708b42676edf3d2e8f85b3c22b9e3be3cf43eb8Diego Colantoni- (void)testIsBase64ReturnsFalseIfStringIsNotValidBase64 {
2708b42676edf3d2e8f85b3c22b9e3be3cf43eb8Diego Colantoni BOOL result = [FRAQRUtils isBase64:@"somethingTHATisNOT%valid1244+"];
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni NSString *decodedString = [FRAQRUtils decode:nil];
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni- (void)testDecodeStringWithNoEscapedCharactersReturnsString {
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni NSString *encodedString = @"anystringwithnoescapedcharacters";
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni NSString *decodedString = [FRAQRUtils decode:encodedString];
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni XCTAssertEqualObjects(decodedString, encodedString);
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni- (void)testDecodeStringWithEscapedCharactersReturnsDecodedString {
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni NSString *encodedString = @"Weight%E6%BC%A2%E5%AD%97Watchers";
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni NSString *decodedString = [FRAQRUtils decode:encodedString];
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni XCTAssertEqualObjects(decodedString, @"Weightæ¼¢å—Watchers");
eea09ddc6e4b4287103c8500027f3e65b5470280Diego Colantoni- (void)testDecodeEmptyStringReturnsEmptyString {