2017-01-07 04:08:28 +08:00
|
|
|
//
|
|
|
|
// UtilsTests.swift
|
|
|
|
// ShadowsocksX-NG
|
|
|
|
//
|
|
|
|
// Created by Rainux Luo on 07/01/2017.
|
|
|
|
// Copyright © 2017 qiuyuzhou. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
2017-01-07 06:54:31 +08:00
|
|
|
@testable import ShadowsocksX_NG
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
class UtilsTests: XCTestCase {
|
|
|
|
|
|
|
|
override func setUp() {
|
|
|
|
super.setUp()
|
|
|
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDown() {
|
|
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
|
|
super.tearDown()
|
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithPlainURL() {
|
|
|
|
let url = URL(string: "ss://aes-256-cfb:password@example.com:8388")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)?.toDictionary()
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNotNil(profile)
|
|
|
|
|
|
|
|
XCTAssertEqual(profile?["ServerHost"] as? String, "example.com")
|
|
|
|
XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388)
|
|
|
|
XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb")
|
|
|
|
XCTAssertEqual(profile?["Password"] as? String, "password")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithPlainURLandQuery() {
|
|
|
|
let url = URL(string: "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)?.toDictionary()
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNotNil(profile)
|
|
|
|
|
|
|
|
XCTAssertEqual(profile?["ServerHost"] as? String, "example.com")
|
|
|
|
XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388)
|
|
|
|
XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb")
|
|
|
|
XCTAssertEqual(profile?["Password"] as? String, "password")
|
2017-01-07 08:51:57 +08:00
|
|
|
XCTAssertEqual(profile?["Remark"] as? String, "Prism")
|
|
|
|
XCTAssertEqual(profile?["OTA"] as? Bool, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithPlainURLandAnotherQuery() {
|
|
|
|
let url = URL(string: "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=0")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)?.toDictionary()
|
2017-01-07 08:51:57 +08:00
|
|
|
|
|
|
|
XCTAssertNotNil(profile)
|
|
|
|
|
|
|
|
XCTAssertEqual(profile?["ServerHost"] as? String, "example.com")
|
|
|
|
XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388)
|
|
|
|
XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb")
|
|
|
|
XCTAssertEqual(profile?["Password"] as? String, "password")
|
|
|
|
XCTAssertEqual(profile?["Remark"] as? String, "Prism")
|
|
|
|
XCTAssertEqual(profile?["OTA"] as? Bool, false)
|
2017-01-07 04:08:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithBase64EncodedURL() {
|
|
|
|
// "ss://aes-256-cfb:password@example.com:8388"
|
|
|
|
let url = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OA")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)?.toDictionary()
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNotNil(profile)
|
|
|
|
|
|
|
|
XCTAssertEqual(profile?["ServerHost"] as? String, "example.com")
|
|
|
|
XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388)
|
|
|
|
XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb")
|
|
|
|
XCTAssertEqual(profile?["Password"] as? String, "password")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithBase64EncodedURLandQuery() {
|
|
|
|
// "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true"
|
|
|
|
let url = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OD9SZW1hcms9UHJpc20mT1RBPXRydWU")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)?.toDictionary()
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNotNil(profile)
|
|
|
|
|
|
|
|
XCTAssertEqual(profile?["ServerHost"] as? String, "example.com")
|
|
|
|
XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388)
|
|
|
|
XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb")
|
|
|
|
XCTAssertEqual(profile?["Password"] as? String, "password")
|
2017-01-07 08:51:57 +08:00
|
|
|
XCTAssertEqual(profile?["Remark"] as? String, "Prism")
|
|
|
|
XCTAssertEqual(profile?["OTA"] as? Bool, true)
|
2017-01-07 04:08:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithEmptyURL() {
|
|
|
|
let url = URL(string: "ss://")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNil(profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithInvalidURL() {
|
|
|
|
let url = URL(string: "ss://invalid url")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNil(profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testParseSSURLwithBase64EncodedInvalidURL() {
|
|
|
|
// "ss://invalid url"
|
|
|
|
let url = URL(string: "ss://aW52YWxpZCB1cmw")
|
|
|
|
|
2017-01-09 21:49:09 +08:00
|
|
|
let profile = ServerProfile(url: url)
|
2017-01-07 04:08:28 +08:00
|
|
|
|
|
|
|
XCTAssertNil(profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testPerformanceExample() {
|
|
|
|
// This is an example of a performance test case.
|
|
|
|
self.measure {
|
|
|
|
// Put the code you want to measure the time of here.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|