|
|
@@ -0,0 +1,80 @@ |
|
|
|
|
|
@testable import App |
|
|
|
|
|
import Fluent |
|
|
|
|
|
import XCTVapor |
|
|
|
|
|
|
|
|
|
|
|
final class AppTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
|
|
func testUsersIndex() async throws{ |
|
|
|
|
|
let app = Application(.testing) |
|
|
|
|
|
defer { app.shutdown() } |
|
|
|
|
|
try await configure(app) |
|
|
|
|
|
try app.test(.GET, "api/v2.0/users/", afterResponse: { res in |
|
|
|
|
|
XCTAssertEqual(res.status, .ok) |
|
|
|
|
|
XCTAssertEqual(res.headers.contentType, .json) |
|
|
|
|
|
_ = try res.content.decode([mdlUser].self) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testUsersRead() async throws{ |
|
|
|
|
|
let app = Application(.testing) |
|
|
|
|
|
defer{app.shutdown()} |
|
|
|
|
|
try await configure(app) |
|
|
|
|
|
let basepath = "api/v2.0/users/" |
|
|
|
|
|
let parameter = try CustomCrypto.EncryptString(input: "1") |
|
|
|
|
|
print(parameter) |
|
|
|
|
|
let path = "\(basepath)\(parameter)" |
|
|
|
|
|
try app.test(.GET, path, afterResponse: { res in |
|
|
|
|
|
XCTAssertEqual(res.status, .ok) |
|
|
|
|
|
XCTAssertEqual(res.headers.contentType, .json) |
|
|
|
|
|
_ = try res.content.decode(mdlUser.self) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testUserLogin() async throws{ |
|
|
|
|
|
let app = Application(.testing) |
|
|
|
|
|
defer{app.shutdown()} |
|
|
|
|
|
try await configure(app) |
|
|
|
|
|
let api = "api/v2.0/users/login/" |
|
|
|
|
|
let gooduser = "bryckman" |
|
|
|
|
|
let goodpwd = "password" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let baduser = "brycman_" |
|
|
|
|
|
let badpwd = "p@$$w0rd" |
|
|
|
|
|
|
|
|
|
|
|
var combo = "\(gooduser):\(goodpwd)" |
|
|
|
|
|
var parameter = try CustomCrypto.EncryptString(input: combo) |
|
|
|
|
|
var path = "\(api)\(parameter)" |
|
|
|
|
|
try app.test(.GET, path, afterResponse: { |
|
|
|
|
|
res in |
|
|
|
|
|
XCTAssertEqual(res.status, .ok) |
|
|
|
|
|
XCTAssertEqual(res.headers.contentType, .json) |
|
|
|
|
|
_ = try res.content.decode(mdlUser.self) |
|
|
|
|
|
}) |
|
|
|
|
|
combo = "\(gooduser):\(badpwd)" |
|
|
|
|
|
parameter = try CustomCrypto.EncryptString(input: combo) |
|
|
|
|
|
path = "\(api)\(parameter)" |
|
|
|
|
|
try app.test(.GET, path, afterResponse: { |
|
|
|
|
|
res in |
|
|
|
|
|
XCTAssertEqual(res.status, .unauthorized) |
|
|
|
|
|
XCTAssertEqual(res.headers.contentType, .json) |
|
|
|
|
|
}) |
|
|
|
|
|
combo = "\(baduser):\(badpwd)" |
|
|
|
|
|
parameter = try CustomCrypto.EncryptString(input: combo) |
|
|
|
|
|
path = "\(api)\(parameter)" |
|
|
|
|
|
try app.test(.GET, path, afterResponse: { |
|
|
|
|
|
res in |
|
|
|
|
|
XCTAssertEqual(res.status, .unauthorized) |
|
|
|
|
|
XCTAssertEqual(res.headers.contentType, .json) |
|
|
|
|
|
}) |
|
|
|
|
|
combo = "\(baduser):\(goodpwd)" |
|
|
|
|
|
parameter = try CustomCrypto.EncryptString(input: combo) |
|
|
|
|
|
path = "\(api)\(parameter)" |
|
|
|
|
|
try app.test(.GET, path, afterResponse: { |
|
|
|
|
|
res in |
|
|
|
|
|
XCTAssertEqual(res.status, .unauthorized) |
|
|
|
|
|
XCTAssertEqual(res.headers.contentType, .json) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |