|
4 | 4 | "encoding/json" |
5 | 5 | "errors" |
6 | 6 |
|
| 7 | + "github.com/majd/ipatool/v2/pkg/http" |
7 | 8 | "github.com/majd/ipatool/v2/pkg/keychain" |
8 | 9 | . "github.com/onsi/ginkgo/v2" |
9 | 10 | . "github.com/onsi/gomega" |
@@ -74,6 +75,44 @@ var _ = Describe("AppStore (AccountInfo)", func() { |
74 | 75 | }) |
75 | 76 | }) |
76 | 77 |
|
| 78 | + When("switching accounts", func() { |
| 79 | + var mockCookieJar *http.MockCookieJar |
| 80 | + |
| 81 | + BeforeEach(func() { |
| 82 | + mockCookieJar = http.NewMockCookieJar(ctrl) |
| 83 | + appstore = NewAppStore(Args{ |
| 84 | + Keychain: mockKeychain, |
| 85 | + CookieJar: mockCookieJar, |
| 86 | + }) |
| 87 | + |
| 88 | + accountStorage := AccountStorage{ |
| 89 | + Current: testEmail, |
| 90 | + Accounts: []Account{ |
| 91 | + {Email: testEmail, Name: testName}, |
| 92 | + {Email: "other@example.com", Name: "Other"}, |
| 93 | + }, |
| 94 | + } |
| 95 | + storageData, err := json.Marshal(accountStorage) |
| 96 | + Expect(err).ToNot(HaveOccurred()) |
| 97 | + |
| 98 | + mockKeychain.EXPECT(). |
| 99 | + Get(AccountKey). |
| 100 | + Return(storageData, nil). |
| 101 | + AnyTimes() |
| 102 | + mockKeychain.EXPECT(). |
| 103 | + Set(AccountKey, gomock.Any()). |
| 104 | + Return(nil) |
| 105 | + mockCookieJar.EXPECT(). |
| 106 | + Reset(). |
| 107 | + Return(nil) |
| 108 | + }) |
| 109 | + |
| 110 | + It("resets session cookies before switching", func() { |
| 111 | + _, err := appstore.SwitchAccount("other@example.com") |
| 112 | + Expect(err).ToNot(HaveOccurred()) |
| 113 | + }) |
| 114 | + }) |
| 115 | + |
77 | 116 | When("keychain returns error", func() { |
78 | 117 | BeforeEach(func() { |
79 | 118 | mockKeychain.EXPECT(). |
|
0 commit comments