github.com/versent/saml2aws@v2.17.0+incompatible/helper/osxkeychain/osxkeychain_darwin_test.go (about) 1 // Copyright (c) 2016 David Calavera 2 3 // Permission is hereby granted, free of charge, to any person obtaining 4 // a copy of this software and associated documentation files (the 5 // "Software"), to deal in the Software without restriction, including 6 // without limitation the rights to use, copy, modify, merge, publish, 7 // distribute, sublicense, and/or sell copies of the Software, and to 8 // permit persons to whom the Software is furnished to do so, subject to 9 // the following conditions: 10 11 // The above copyright notice and this permission notice shall be 12 // included in all copies or substantial portions of the Software. 13 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 // 22 // https://github.com/docker/docker-credential-helpers 23 package osxkeychain 24 25 import ( 26 "testing" 27 28 "github.com/versent/saml2aws/helper/credentials" 29 ) 30 31 func TestOSXKeychainHelper(t *testing.T) { 32 creds := &credentials.Credentials{ 33 ServerURL: "https://foobar.docker.io:2376/v1", 34 Username: "foobar", 35 Secret: "foobarbaz", 36 } 37 creds1 := &credentials.Credentials{ 38 ServerURL: "https://foobar.docker.io:2376/v2", 39 Username: "foobarbaz", 40 Secret: "foobar", 41 } 42 helper := Osxkeychain{} 43 if err := helper.Add(creds); err != nil { 44 t.Fatal(err) 45 } 46 47 username, secret, err := helper.Get(creds.ServerURL) 48 if err != nil { 49 t.Fatal(err) 50 } 51 52 if username != "foobar" { 53 t.Fatalf("expected %s, got %s\n", "foobar", username) 54 } 55 56 if secret != "foobarbaz" { 57 t.Fatalf("expected %s, got %s\n", "foobarbaz", secret) 58 } 59 60 auths, err := helper.List() 61 if err != nil || len(auths) == 0 { 62 t.Fatal(err) 63 } 64 65 helper.Add(creds1) 66 defer helper.Delete(creds1.ServerURL) 67 newauths, err := helper.List() 68 if len(newauths)-len(auths) != 1 { 69 if err == nil { 70 t.Fatalf("Error: len(newauths): %d, len(auths): %d", len(newauths), len(auths)) 71 } 72 t.Fatalf("Error: len(newauths): %d, len(auths): %d\n Error= %v", len(newauths), len(auths), err) 73 } 74 75 if err := helper.Delete(creds.ServerURL); err != nil { 76 t.Fatal(err) 77 } 78 } 79 80 func TestMissingCredentials(t *testing.T) { 81 helper := Osxkeychain{} 82 _, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd") 83 if !credentials.IsErrCredentialsNotFound(err) { 84 t.Fatalf("expected ErrCredentialsNotFound, got %v", err) 85 } 86 }