github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/db/migration/update_auth_providers_test.go (about) 1 package migration_test 2 3 import ( 4 "database/sql" 5 6 . "github.com/onsi/ginkgo" 7 ) 8 9 var _ = Describe("Update auth providers", func() { 10 const preMigrationVersion = 1513895878 11 const postMigrationVersion = 1516643303 12 13 var ( 14 db *sql.DB 15 ) 16 17 Context("Down", func() { 18 It("migrates basic auth data to separate field", func() { 19 20 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 21 SetupTeam(db, "main", `{"basicauth": {"username": "username", "password": "password"}}`) 22 db.Close() 23 24 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 25 ExpectTeamWithBasicAuth(db, "main", "username", "password") 26 db.Close() 27 }) 28 29 It("does not modify existing providers", func() { 30 31 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 32 SetupTeam(db, "main", `{"github": {"client_id": "some-client-id", "client_secret": "some-client-secret"}}`) 33 db.Close() 34 35 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 36 ExpectTeamWithGithubProvider(db, "main", "some-client-id", "some-client-secret") 37 db.Close() 38 }) 39 40 It("removes the basicauth provider from providers list", func() { 41 42 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 43 SetupTeam(db, "main", `{"basicauth": {"username": "username", "password": "password"}}`) 44 db.Close() 45 46 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 47 ExpectTeamWithoutBasicAuthProvider(db, "main") 48 db.Close() 49 }) 50 51 It("removes the noauth provider from providers list", func() { 52 53 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 54 SetupTeam(db, "main", `{"noauth": {"noauth": true}}`) 55 db.Close() 56 57 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 58 ExpectTeamWithoutNoAuthProvider(db, "main") 59 db.Close() 60 }) 61 }) 62 63 Context("Up", func() { 64 It("migrates basic auth data to empty providers", func() { 65 66 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 67 SetupTeamWithBasicAuth(db, "main", `{"basic_auth_username": "username", "basic_auth_password": "password"}`, ``) 68 db.Close() 69 70 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 71 ExpectTeamWithBasicAuthProvider(db, "main", "username", "password") 72 db.Close() 73 }) 74 75 It("migrates basic auth data to null providers", func() { 76 77 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 78 SetupTeamWithBasicAuth(db, "main", `{"basic_auth_username": "username", "basic_auth_password": "password"}`, `null`) 79 db.Close() 80 81 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 82 ExpectTeamWithBasicAuthProvider(db, "main", "username", "password") 83 db.Close() 84 }) 85 86 It("merges basic auth data with existing providers", func() { 87 88 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 89 SetupTeamWithBasicAuth(db, "main", `{"basic_auth_username": "username", "basic_auth_password": "password"}`, `{"github": {"client_id": "some-client-id", "client_secret": "some-client-secret"}}`) 90 db.Close() 91 92 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 93 ExpectTeamWithBasicAuthProvider(db, "main", "username", "password") 94 ExpectTeamWithGithubProvider(db, "main", "some-client-id", "some-client-secret") 95 db.Close() 96 }) 97 98 It("does not migrate malformed basic auth data", func() { 99 100 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 101 SetupTeamWithBasicAuth(db, "main", `{"u": "username", "p": "password"}`, ``) 102 db.Close() 103 104 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 105 ExpectTeamWithoutBasicAuthProvider(db, "main") 106 db.Close() 107 }) 108 109 It("does not migrate empty json basic auth data", func() { 110 111 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 112 SetupTeamWithBasicAuth(db, "main-empty", `{}`, ``) 113 SetupTeamWithBasicAuth(db, "main-null", `null`, ``) 114 db.Close() 115 116 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 117 ExpectTeamWithoutBasicAuthProvider(db, "main-empty") 118 ExpectTeamWithoutBasicAuthProvider(db, "main-null") 119 db.Close() 120 }) 121 122 It("does not add noauth provider when basic auth is configured", func() { 123 124 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 125 SetupTeamWithBasicAuth(db, "main", `{"basic_auth_username": "username", "basic_auth_password": "password"}`, ``) 126 db.Close() 127 128 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 129 ExpectTeamWithoutNoAuthProvider(db, "main") 130 db.Close() 131 }) 132 133 It("does not add noauth provider when there are existing providers", func() { 134 135 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 136 SetupTeamWithBasicAuth(db, "main", `{}`, `{"github": {"client_id": "some-client-id", "client_secret": "some-client-secret"}}`) 137 db.Close() 138 139 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 140 ExpectTeamWithoutNoAuthProvider(db, "main") 141 db.Close() 142 }) 143 144 It("adds noauth provider when no other auth methods are configured", func() { 145 146 db = postgresRunner.OpenDBAtVersion(preMigrationVersion) 147 SetupTeamWithBasicAuth(db, "main-empty-blank", `{}`, ``) 148 SetupTeamWithBasicAuth(db, "main-null-blank", `null`, ``) 149 SetupTeamWithBasicAuth(db, "main-empty-empty", `{}`, `{}`) 150 db.Close() 151 152 db = postgresRunner.OpenDBAtVersion(postMigrationVersion) 153 ExpectTeamWithNoAuthProvider(db, "main-empty-blank", true) 154 ExpectTeamWithNoAuthProvider(db, "main-null-blank", true) 155 ExpectTeamWithNoAuthProvider(db, "main-empty-empty", true) 156 db.Close() 157 }) 158 }) 159 })