github.com/openshift-online/ocm-sdk-go@v0.1.473/authentication/securestore/keychain_test.go (about) 1 //go:build darwin 2 // +build darwin 3 4 /* 5 Copyright (c) 2024 Red Hat, Inc. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package securestore 21 22 import ( 23 "time" 24 25 . "github.com/onsi/ginkgo/v2" // nolint 26 . "github.com/onsi/gomega" // nolint 27 28 . "github.com/openshift-online/ocm-sdk-go/testing" // nolint 29 ) 30 31 var _ = Describe("Keychain", func() { 32 const backend = "keychain" 33 34 BeforeEach(func() { 35 err := RemoveConfigFromKeyring(backend) 36 Expect(err).To(BeNil()) 37 }) 38 39 When("Listing Keyrings", func() { 40 It("Lists keychain as a valid keyring", func() { 41 backends := AvailableBackends() 42 Expect(backends).To(ContainElement(backend)) 43 }) 44 }) 45 46 When("Using Keychain", func() { 47 It("Stores/Removes via Keychain", func() { 48 // Create the token 49 accessToken := MakeTokenString("Bearer", 15*time.Minute) 50 51 // Run insert 52 err := UpsertConfigToKeyring(backend, []byte(accessToken)) 53 54 Expect(err).To(BeNil()) 55 56 // Check the content of the keyring 57 result, err := GetConfigFromKeyring(backend) 58 Expect(result).To(Equal([]byte(accessToken))) 59 Expect(err).To(BeNil()) 60 61 // Remove the configuration from the keyring 62 err = RemoveConfigFromKeyring(backend) 63 Expect(err).To(BeNil()) 64 65 // Ensure the keyring is empty 66 result, err = GetConfigFromKeyring(backend) 67 Expect(result).To(Equal([]byte(""))) 68 Expect(err).To(BeNil()) 69 }) 70 }) 71 })