FRAQRUtilsTests.m revision a4c96a094a3d715ef793b60cfabfdb2ee088b319
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell/*
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 * License.
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell *
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 *
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 *
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell * Copyright 2016 ForgeRock AS.
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell */
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell#import <XCTest/XCTest.h>
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell#import "FRAQRUtils.h"
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell@interface FRAQRUtilsTests : XCTestCase
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell@end
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell@implementation FRAQRUtilsTests
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell- (void)testReplaceCharactersForURLDecodingReplacesDashes {
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *content = @"-123-456-";
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *result = [FRAQRUtils replaceCharactersForURLDecoding:content];
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell XCTAssertEqualObjects(result, @"+123+456+");
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell}
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell- (void)testReplaceCharactersForURLDecodingReplacesUnderscores {
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *content = @"_123_456_";
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *result = [FRAQRUtils replaceCharactersForURLDecoding:content];
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell XCTAssertEqualObjects(result, @"/123/456/");
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell}
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell- (void)testReplaceCharactersForURLDecodingDoesntReplaceIfValid {
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *content = @"123456";
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell NSString *result = [FRAQRUtils replaceCharactersForURLDecoding:content];
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell XCTAssertEqualObjects(result, @"123456");
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell}
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni- (void)testDecodeBase64NilReturnsNil {
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni NSData *result = [FRAQRUtils decodeBase64:nil];
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni XCTAssertNil(result);
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni}
a4c96a094a3d715ef793b60cfabfdb2ee088b319Diego Colantoni
465ea459a87d4605e145d8f45b6a9c104b696e3bCraig McDonnell@end