(t *testing.T)
| 337 | } |
| 338 | |
| 339 | func TestGetAccountWithEmailAlreadyExists(t *testing.T) { |
| 340 | ctx := context.Background() |
| 341 | |
| 342 | am := &ACMEIssuer{CA: dummyCA, Logger: zap.NewNop(), mu: new(sync.Mutex)} |
| 343 | testConfig := &Config{ |
| 344 | Issuers: []Issuer{am}, |
| 345 | Storage: &recordingStorage{Storage: &memoryStorage{}}, |
| 346 | Logger: defaultTestLogger, |
| 347 | certCache: new(Cache), |
| 348 | } |
| 349 | am.config = testConfig |
| 350 | |
| 351 | email := "me@foobar.com" |
| 352 | |
| 353 | // Set up test |
| 354 | account, err := am.newAccount(email) |
| 355 | if err != nil { |
| 356 | t.Fatalf("Error creating account: %v", err) |
| 357 | } |
| 358 | err = am.saveAccount(ctx, am.CA, account) |
| 359 | if err != nil { |
| 360 | t.Fatalf("Error saving account: %v", err) |
| 361 | } |
| 362 | |
| 363 | // Set the expected email: |
| 364 | am.Email = email |
| 365 | err = am.setEmail(ctx, true) |
| 366 | if err != nil { |
| 367 | t.Fatalf("setEmail error: %v", err) |
| 368 | } |
| 369 | |
| 370 | // Expect to load account from disk |
| 371 | keyBytes, err := PEMEncodePrivateKey(account.PrivateKey) |
| 372 | if err != nil { |
| 373 | t.Fatalf("Error encoding private key: %v", err) |
| 374 | } |
| 375 | |
| 376 | loadedAccount, err := am.GetAccount(ctx, keyBytes) |
| 377 | if err != nil { |
| 378 | t.Fatalf("Error getting account: %v", err) |
| 379 | } |
| 380 | |
| 381 | // Assert keys are the same |
| 382 | if !privateKeysSame(account.PrivateKey, loadedAccount.PrivateKey) { |
| 383 | t.Error("Expected private key to be the same after loading, but it wasn't") |
| 384 | } |
| 385 | |
| 386 | // Assert emails are the same |
| 387 | if !reflect.DeepEqual(account.Contact, loadedAccount.Contact) { |
| 388 | t.Errorf("Expected contacts to be equal, but was '%s' before and '%s' after loading", account.Contact, loadedAccount.Contact) |
| 389 | } |
| 390 | |
| 391 | // Assert that this was found without listing all accounts |
| 392 | rs := testConfig.Storage.(*recordingStorage) |
| 393 | for _, call := range rs.calls { |
| 394 | if call.name == "List" { |
| 395 | t.Error("Unexpected List call") |
| 396 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…