<commit_before>//  ----------------------------------------------------------------
//  Created by <NAME> on 08/02/2018.
//
//  Copyright (c) 2017-present, <NAME>, <NAME>, et al.
//
//  This source code is licensed under the MIT license found in the
//  LICENSE file in the root directory of this source tree.
//  ----------------------------------------------------------------

import XCTest

let testRegistrationData = "<KEY>"
let testClientData = "<KEY>"
let testRegisterChallenge = "{\"challenge\":\"\(testChallenge)\",\"version\":\"U2F_V2\",\"appId\":\"\(testAppId)\"}"
let testRegisterResponse = "{ \"registrationData\": \"\(testRegistrationData)\", \"clientData\": \"\(testClientData)\" }"


/*
//{ "registrationData": "<KEY>", "clientData": "<KEY>" }let signChallenge = "{\"version\":\"U2F_V2\",\"challenge\":\"ZR-2IyxSFTSoQ00GOMN6hrQC5qmXXoDyG7PmwYYWUTw\",\"keyHandle\":\"oea6fGi-MGzyGGrJzb2LFdvCm9KCOy-gVuW4hgSXwNz7koDuZcnP7X4K9MK5DX2wwxud_QRqjmuWhIqGIYhUta5g6f36_b_QO1hzvBO8vb8\",\"appId\":\"https://demo.yubico.com\"}"
*/

let testSignatureData = "AQAAABcwRgIhAPpHzFHIVZRGlSJvOJ452d3Cbxd00pObjwKZVbWfHt7PAiEArliUes968d98oTENLS-BC1Vkwrxw59yb5Q0KLTtM6hE"
let testSignChallenge = "{ \"version\":\"U2F_V2\",\"challenge\":\"\(testChallenge)\",\"keyHandle\":\"\(testKeyHandle)\",\"appId\":\"\(testAppId)\"}"
let testSignResponse = "{ \"signatureData\": \"\(testSignatureData)\", \"clientData\": \"\(testClientData)\", \"keyHandle\": \"\(testKeyHandle)\" }"

class MockDevice : U2FDevice {
    let response : String
    var request = ""
    
    init(response : String) throws {
        self.response = response
        try super.init()
    }
    
    override func register_(jsonRequest: String, origin: String) throws -> String {
        request = jsonRequest
        return response
    }

    override func sign_(jsonRequest: String, origin: String) throws -> String {
        request = jsonRequest
        return response
    }

}

class U2FDeviceTests: XCTestCase {

    func testRegister() {
        guard let request = U2FRegisterRequest(requestDictionary: testRegisterRequest, origin: testOrigin) else {
            XCTFail()
            return
        }
        
        do {
            let device = try MockDevice(response: testRegisterResponse)
            let response = try device.perform(request: request)
            
            print(device.request)
            
            XCTAssertEqual(response.type, U2FRegisterRequest.ResponseType)
            XCTAssertEqual(response.requestId, request.requestId)
            
            let responseData = response.responseData as! [String:Any]

            guard let registrationData = responseData["registrationData"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(registrationData, testRegistrationData)

            guard let clientData = responseData["clientData"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(clientData, testClientData)

        } catch {
            XCTFail()
        }
        
    }

    func testSign() {
        guard let request = U2FSignRequest(requestDictionary: testSignRequest, origin: testOrigin) else {
            XCTFail()
            return
        }
        
        do {
            let device = try MockDevice(response: testSignResponse)
            let response = try device.perform(request: request)

            print(device.request)

            XCTAssertEqual(response.type, U2FSignRequest.ResponseType)
            XCTAssertEqual(response.requestId, request.requestId)
            
            let responseData = response.responseData as! [String:Any]
            
            guard let keyHandle = responseData["keyHandle"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(keyHandle, testKeyHandle)
            
            guard let signatureData = responseData["signatureData"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(signatureData, testSignatureData)
            
        } catch {
            XCTFail()
        }
        
    }

}
<commit_msg>added signing tests<commit_after>//  ----------------------------------------------------------------
//  Created by <NAME> on 08/02/2018.
//
//  Copyright (c) 2017-present, <NAME>, <NAME>, et al.
//
//  This source code is licensed under the MIT license found in the
//  LICENSE file in the root directory of this source tree.
//  ----------------------------------------------------------------

import XCTest

let testAppIdQuoted = "https:\\/\\/demo.yubico.com"
let testRegistrationData = "<KEY>"
let testClientData = "<KEY>"
let testRegisterChallenge = "{\"challenge\":\"\(testChallenge)\",\"version\":\"U2F_V2\",\"appId\":\"\(testAppIdQuoted)\"}"
let testRegisterResponse = "{ \"registrationData\": \"\(testRegistrationData)\", \"clientData\": \"\(testClientData)\" }"


/*
//{ "registrationData": "<KEY>", "clientData": "<KEY> }let signChallenge = "{\"version\":\"U2F_V2\",\"challenge\":\"ZR-2IyxSFTSoQ00GOMN6hrQC5qmXXoDyG7PmwYYWUTw\",\"keyHandle\":\"<KEY>\",\"appId\":\"https://demo.yubico.com\"}"
*/

let testSignatureData = "<KEY>"
let testSignChallenge = "{\"version\":\"U2F_V2\",\"challenge\":\"\(testChallenge)\",\"keyHandle\":\"\(testKeyHandle)\",\"appId\":\"\(testAppIdQuoted)\"}"
let testSignResponse = "{ \"signatureData\": \"\(testSignatureData)\", \"clientData\": \"\(testClientData)\", \"keyHandle\": \"\(testKeyHandle)\" }"

class MockDevice : U2FDevice {
    let response : String
    var request = ""
    
    init(response : String) throws {
        self.response = response
        try super.init()
    }
    
    override func register_(jsonRequest: String, origin: String) throws -> String {
        request = jsonRequest
        return response
    }

    override func sign_(jsonRequest: String, origin: String) throws -> String {
        request = jsonRequest
        return response
    }

}

class U2FDeviceTests: XCTestCase {

    func testRegistrationChallenge() {
        guard let request = U2FRegisterRequest(requestDictionary: testRegisterRequest, origin: testOrigin) else {
            XCTFail()
            return
        }
        
        do {
            let device = try MockDevice(response: testRegisterResponse)
            let _ = try device.perform(request: request)
            XCTAssertEqual(device.request, testRegisterChallenge)
        } catch {
            XCTFail()
        }
    }

    func testRegistrationResponseData() {
        guard let request = U2FRegisterRequest(requestDictionary: testRegisterRequest, origin: testOrigin) else {
            XCTFail()
            return
        }
        
        do {
            let device = try MockDevice(response: testRegisterResponse)
            let response = try device.perform(request: request)
            XCTAssertEqual(response.type, U2FRegisterRequest.ResponseType)
            XCTAssertEqual(response.requestId, request.requestId)
            
            let responseData = response.responseData as! [String:Any]

            guard let registrationData = responseData["registrationData"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(registrationData, testRegistrationData)

            guard let clientData = responseData["clientData"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(clientData, testClientData)

        } catch {
            XCTFail()
        }
        
    }

    func testSigningChallenge() {
        guard let request = U2FSignRequest(requestDictionary: testSignRequest, origin: testOrigin) else {
            XCTFail()
            return
        }
        
        do {
            let device = try MockDevice(response: testSignResponse)
            let _ = try device.perform(request: request)

            XCTAssertEqual(device.request, testSignChallenge)
        } catch {
            XCTFail()
        }
        
    }

    func testSigningResponse() {
        guard let request = U2FSignRequest(requestDictionary: testSignRequest, origin: testOrigin) else {
            XCTFail()
            return
        }
        
        do {
            let device = try MockDevice(response: testSignResponse)
            let response = try device.perform(request: request)
            XCTAssertEqual(response.type, U2FSignRequest.ResponseType)
            XCTAssertEqual(response.requestId, request.requestId)
            
            let responseData = response.responseData as! [String:Any]
            
            guard let keyHandle = responseData["keyHandle"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(keyHandle, testKeyHandle)
            
            guard let signatureData = responseData["signatureData"] as? String else {
                XCTFail()
                return
            }
            XCTAssertEqual(signatureData, testSignatureData)
            
        } catch {
            XCTFail()
        }
        
    }

}

{'fraction_non_alphanumeric': 0.14023991275899672, 'fraction_numerical': 0.010577971646673937, 'mean_word_length': 1.9766309639727362, 'pattern_counts': {'":': 36, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '327193', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2484, 'n_words': 513}