Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
liberty
tunnel
liberty-tunnel-client-library-apple
Commits
83bb3e4d
Commit
83bb3e4d
authored
Nov 29, 2018
by
Jose Blaya
Browse files
Create a method to clean the database to fix login tests
parent
0b39a978
Changes
5
Hide whitespace changes
Inline
Side-by-side
PIALibrary/Sources/Core/Account/AccountProvider.swift
View file @
83bb3e4d
...
...
@@ -80,6 +80,11 @@ public protocol AccountProvider: class {
*/
func
logout
(
_
callback
:
SuccessLibraryCallback
?)
/**
Remove all data from the plain and secure internal database
*/
func
cleanDatabase
()
#if os(iOS)
/**
Lists the available plans with their corresponding product to purchase in order to get them.
...
...
PIALibrary/Sources/Library/Account/DefaultAccountProvider.swift
View file @
83bb3e4d
...
...
@@ -197,13 +197,7 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
guard
isLoggedIn
else
{
preconditionFailure
()
}
if
let
username
=
accessedDatabase
.
secure
.
username
()
{
accessedDatabase
.
secure
.
setPassword
(
nil
,
for
:
username
)
accessedDatabase
.
secure
.
setUsername
(
nil
)
accessedDatabase
.
secure
.
setToken
(
nil
,
for
:
accessedDatabase
.
secure
.
tokenKey
(
for
:
username
))
}
accessedDatabase
.
plain
.
publicUsername
=
nil
accessedDatabase
.
plain
.
accountInfo
=
nil
cleanDatabase
()
Macros
.
postNotification
(
.
PIAAccountDidLogout
)
callback
?(
nil
)
}
...
...
@@ -416,6 +410,19 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
}
}
/**
Remove all data from the plain and secure internal database
*/
func
cleanDatabase
()
{
if
let
username
=
accessedDatabase
.
secure
.
username
()
{
accessedDatabase
.
secure
.
setPassword
(
nil
,
for
:
username
)
accessedDatabase
.
secure
.
setUsername
(
nil
)
accessedDatabase
.
secure
.
setToken
(
nil
,
for
:
accessedDatabase
.
secure
.
tokenKey
(
for
:
username
))
}
accessedDatabase
.
plain
.
publicUsername
=
nil
accessedDatabase
.
plain
.
accountInfo
=
nil
}
#endif
// MARK: WebServicesConsumer
...
...
PIALibrary/Sources/Mock/MockAccountProvider.swift
View file @
83bb3e4d
...
...
@@ -11,7 +11,6 @@ import Foundation
/// Simulates account-related operations
public
class
MockAccountProvider
:
AccountProvider
,
WebServicesConsumer
{
/// Mocks the outcome of a sign-up operation.
///
/// - Seealso: `AccountProvider.signup(...)`
...
...
@@ -170,6 +169,11 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
delegate
.
logout
(
callback
)
}
/// :nodoc:
public
func
cleanDatabase
()
{
delegate
.
cleanDatabase
()
}
#if os(iOS)
/// :nodoc:
public
func
listPlanProducts
(
_
callback
:
(([
Plan
:
InAppProduct
]?,
Error
?)
->
Void
)?)
{
...
...
PIALibrary/Sources/UI/iOS/PIAWelcomeViewController.swift
View file @
83bb3e4d
...
...
@@ -311,7 +311,7 @@ protocol WelcomeCompletionDelegate: class {
}
class
EphemeralAccountProvider
:
AccountProvider
,
ProvidersAccess
,
InAppAccess
{
// XXX: we want legit web services calls, yet allow the option to mock them
private
var
webServices
:
WebServices
?
{
guard
let
accountProvider
=
accessedProviders
.
accountProvider
as?
WebServicesConsumer
else
{
...
...
@@ -373,6 +373,10 @@ class EphemeralAccountProvider: AccountProvider, ProvidersAccess, InAppAccess {
func
logout
(
_
callback
:
SuccessLibraryCallback
?)
{
fatalError
(
"Not implemented"
)
}
func
cleanDatabase
()
{
fatalError
(
"Not implemented"
)
}
func
listPlanProducts
(
_
callback
:
(([
Plan
:
InAppProduct
]?,
Error
?)
->
Void
)?)
{
accessedProviders
.
accountProvider
.
listPlanProducts
(
callback
)
...
...
PIALibraryTests/AccountTests.swift
View file @
83bb3e4d
...
...
@@ -23,11 +23,13 @@ class AccountTests: XCTestCase {
Client
.
database
=
Client
.
Database
(
group
:
"group.com.privateinternetaccess"
)
.
truncate
()
Client
.
bootstrap
()
Client
.
providers
.
accountProvider
.
cleanDatabase
()
}
override
func
tearDown
()
{
super
.
tearDown
()
unregisterNotifications
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment