Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package machinetoken | 5 package machinetoken |
| 6 | 6 |
| 7 // This file contains common mocks used by unit tests. | 7 // This file contains common mocks used by unit tests. |
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "crypto" | 10 "crypto" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 uwi+mmV6pbwEPKYNHpxHXSbEFnWwnZm1OtM28sP9O0D94XzRq2OfWiiD | 87 uwi+mmV6pbwEPKYNHpxHXSbEFnWwnZm1OtM28sP9O0D94XzRq2OfWiiD |
| 88 -----END CERTIFICATE-----` | 88 -----END CERTIFICATE-----` |
| 89 | 89 |
| 90 const expectedLuciMachineToken = `CkkKJGx1Y2ktdG9rZW4tc2VydmVyLXRlc3QtMS5mYWtlLm RvbW` + | 90 const expectedLuciMachineToken = `CkkKJGx1Y2ktdG9rZW4tc2VydmVyLXRlc3QtMS5mYWtlLm RvbW` + |
| 91 `FpbhITc2lnbmVyQHRlc3RpbmcuaG9zdBjykcGmBSCQHCh7MIAgEihmOWRhNWEwZDA5MDN` + | 91 `FpbhITc2lnbmVyQHRlc3RpbmcuaG9zdBjykcGmBSCQHCh7MIAgEihmOWRhNWEwZDA5MDN` + |
| 92 `iZGE1OGM2ZDY2NGUzODUyYTg5YzI4M2Q3ZmU5GkCrjVagpGYIIVo/OsbQD4Jg8Jbp1l/6` + | 92 `iZGE1OGM2ZDY2NGUzODUyYTg5YzI4M2Q3ZmU5GkCrjVagpGYIIVo/OsbQD4Jg8Jbp1l/6` + |
| 93 `Q+9t+jHpBXcennnPVb0tKWojPYN3195lZ1ESofXz8rDnXoYF4/2X2pDn` | 93 `Q+9t+jHpBXcennnPVb0tKWojPYN3195lZ1ESofXz8rDnXoYF4/2X2pDn` |
| 94 | 94 |
| 95 var testingTime = time.Date(2015, time.February, 3, 4, 5, 6, 0, time.UTC) | 95 var testingTime = time.Date(2015, time.February, 3, 4, 5, 6, 0, time.UTC) |
| 96 | 96 |
| 97 var testingCA = certconfig.CA{ | 97 var testingCA = certconfig.CA{ |
|
iannucci
2017/06/20 22:43:19
@smut: here's the definition of testingCA
Vadim Sh.
2017/06/20 22:46:01
yeah... I have no good method of defining global t
| |
| 98 CN: "Fake CA: fake.ca", | 98 CN: "Fake CA: fake.ca", |
| 99 ParsedConfig: &admin.CertificateAuthorityConfig{ | 99 ParsedConfig: &admin.CertificateAuthorityConfig{ |
| 100 UniqueId: 123, | 100 UniqueId: 123, |
| 101 KnownDomains: []*admin.DomainConfig{ | 101 KnownDomains: []*admin.DomainConfig{ |
| 102 { | 102 { |
| 103 Domain: []string{"fake.domain"}, | 103 Domain: []string{"fake.domain"}, |
| 104 MachineTokenLifetime: 3600, | 104 MachineTokenLifetime: 3600, |
| 105 }, | 105 }, |
| 106 }, | 106 }, |
| 107 }, | 107 }, |
| 108 AddedRev: "cfg-added-rev", | 108 AddedRev: "cfg-added-rev", |
| 109 UpdatedRev: "cfg-updated-rev", | 109 UpdatedRev: "cfg-updated-rev", |
| 110 } | 110 } |
| 111 | 111 |
| 112 func testingContext() context.Context { | 112 func testingContext(ca certconfig.CA) context.Context { |
| 113 ctx := gaetesting.TestingContext() | 113 ctx := gaetesting.TestingContext() |
| 114 ctx = info.GetTestable(ctx).SetRequestID("gae-request-id") | 114 ctx = info.GetTestable(ctx).SetRequestID("gae-request-id") |
| 115 ctx, _ = testclock.UseTime(ctx, testingTime) | 115 ctx, _ = testclock.UseTime(ctx, testingTime) |
| 116 | 116 |
| 117 // Put mocked CA config in the datastore. | 117 // Put mocked CA config in the datastore. |
| 118 » ca := testingCA | 118 » ds.Put(ctx, &ca) |
| 119 » ds.Put(ctx, &ca) // put a copy, Put modifies the object | |
| 120 certconfig.StoreCAUniqueIDToCNMap(ctx, map[int64]string{ | 119 certconfig.StoreCAUniqueIDToCNMap(ctx, map[int64]string{ |
| 121 ca.ParsedConfig.UniqueId: ca.CN, | 120 ca.ParsedConfig.UniqueId: ca.CN, |
| 122 }) | 121 }) |
| 123 certconfig.UpdateCRLSet(ctx, ca.CN, certconfig.CRLShardCount, &pkix.Cert ificateList{}) | 122 certconfig.UpdateCRLSet(ctx, ca.CN, certconfig.CRLShardCount, &pkix.Cert ificateList{}) |
| 124 | 123 |
| 125 return ctx | 124 return ctx |
| 126 } | 125 } |
| 127 | 126 |
| 128 func testingSigner() signing.Signer { | 127 func testingSigner() signing.Signer { |
| 129 return signingtest.NewSigner(0, &signing.ServiceInfo{ | 128 return signingtest.NewSigner(0, &signing.ServiceInfo{ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 if err != nil { | 176 if err != nil { |
| 178 panic(err) | 177 panic(err) |
| 179 } | 178 } |
| 180 return crt | 179 return crt |
| 181 } | 180 } |
| 182 | 181 |
| 183 func getTestCertDER() []byte { | 182 func getTestCertDER() []byte { |
| 184 block, _ := pem.Decode([]byte(cert)) | 183 block, _ := pem.Decode([]byte(cert)) |
| 185 return block.Bytes | 184 return block.Bytes |
| 186 } | 185 } |
| OLD | NEW |