Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get username from filepath. #265

Merged
merged 1 commit into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion passExtension/Controllers/ExtensionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ExtensionViewController: UIViewController, UITableViewDataSource, UITableV
var decryptedPassword: Password?
do {
decryptedPassword = try self.passwordStore.decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: self.requestPGPKeyPassphrase)
let username = decryptedPassword?.username ?? decryptedPassword?.login ?? ""
let username = decryptedPassword?.username ?? decryptedPassword?.login ?? decryptedPassword?.nameFromPath ?? ""
let password = decryptedPassword?.password ?? ""
DispatchQueue.main.async {// prepare a dictionary to return
switch self.extensionAction {
Expand Down
4 changes: 4 additions & 0 deletions passKit/Models/Password.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class Password {
return url.deletingPathExtension().path
}

public var nameFromPath: String? {
return url.deletingPathExtension().path.split(separator: "/").last.map { String($0) }
}

public var password: String {
return parser.firstLine
}
Expand Down
7 changes: 7 additions & 0 deletions passKitTests/Models/PasswordTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ class PasswordTest: XCTestCase {
XCTAssert(MULTILINE_LINE_START.title => "" ∈ password)
}

func testUsernameInPath() {
let password = getPasswordObjectWith(content: "", url: URL(fileURLWithPath: "exampleservice/exampleusername.pgp"))

XCTAssertEqual(password.nameFromPath, "exampleusername")
}


func testMultilineValues() {
let lineBreakField = "with line breaks" => "|\n This is \n text spread over \n multiple lines! "
let noLineBreakField = "without line breaks" => " > \n This is \n text spread over\n multiple lines!"
Expand Down