go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/appengine/gaesecrets/gaesecrets_test.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gaesecrets 16 17 import ( 18 "context" 19 "testing" 20 21 "go.chromium.org/luci/gae/impl/memory" 22 "go.chromium.org/luci/server/caching" 23 "go.chromium.org/luci/server/secrets" 24 25 . "github.com/smartystreets/goconvey/convey" 26 ) 27 28 func TestWorks(t *testing.T) { 29 Convey("gaesecrets.Store works", t, func() { 30 c := Use(memory.Use(context.Background()), nil) 31 c = caching.WithEmptyProcessCache(c) 32 33 // Autogenerates one. 34 s1, err := secrets.RandomSecret(c, "key1") 35 So(err, ShouldBeNil) 36 So(len(s1.Active), ShouldEqual, 32) 37 38 // Returns same one. 39 s2, err := secrets.RandomSecret(c, "key1") 40 So(err, ShouldBeNil) 41 So(s2, ShouldResemble, s1) 42 43 // Can also be fetched as stored. 44 s3, err := secrets.StoredSecret(c, "key1") 45 So(err, ShouldBeNil) 46 So(s3, ShouldResemble, s1) 47 48 // Missing stored secrets are not auto-generated though. 49 _, err = secrets.StoredSecret(c, "key2") 50 So(err, ShouldEqual, secrets.ErrNoSuchSecret) 51 }) 52 }