How to use UpdateConfig method of client Package

Best Testkube code snippet using client.UpdateConfig

oauth_test.go

Source:oauth_test.go Github

copy

Full Screen

...16 AdminClient := th.SystemAdminClient17 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider18 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations19 defer func() {20 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })21 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })22 }()23 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })24 utils.SetDefaultRolesBasedOnConfig()25 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}, IsTrusted: true}26 rapp, resp := AdminClient.CreateOAuthApp(oapp)27 CheckNoError(t, resp)28 CheckCreatedStatus(t, resp)29 if rapp.Name != oapp.Name {30 t.Fatal("names did not match")31 }32 if rapp.IsTrusted != oapp.IsTrusted {33 t.Fatal("trusted did no match")34 }35 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })36 utils.SetDefaultRolesBasedOnConfig()37 _, resp = Client.CreateOAuthApp(oapp)38 CheckForbiddenStatus(t, resp)39 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })40 utils.SetDefaultRolesBasedOnConfig()41 rapp, resp = Client.CreateOAuthApp(oapp)42 CheckNoError(t, resp)43 CheckCreatedStatus(t, resp)44 if rapp.IsTrusted {45 t.Fatal("trusted should be false - created by non admin")46 }47 oapp.Name = ""48 _, resp = AdminClient.CreateOAuthApp(oapp)49 CheckBadRequestStatus(t, resp)50 if r, err := Client.DoApiPost("/oauth/apps", "garbage"); err == nil {51 t.Fatal("should have failed")52 } else {53 if r.StatusCode != http.StatusBadRequest {54 t.Log("actual: " + strconv.Itoa(r.StatusCode))55 t.Log("expected: " + strconv.Itoa(http.StatusBadRequest))56 t.Fatal("wrong status code")57 }58 }59 Client.Logout()60 _, resp = Client.CreateOAuthApp(oapp)61 CheckUnauthorizedStatus(t, resp)62 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })63 oapp.Name = GenerateTestAppName()64 _, resp = AdminClient.CreateOAuthApp(oapp)65 CheckNotImplementedStatus(t, resp)66}67func TestUpdateOAuthApp(t *testing.T) {68 th := Setup().InitBasic().InitSystemAdmin()69 defer th.TearDown()70 Client := th.Client71 AdminClient := th.SystemAdminClient72 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider73 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations74 defer func() {75 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })76 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })77 }()78 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })79 utils.SetDefaultRolesBasedOnConfig()80 oapp := &model.OAuthApp{81 Name: "oapp",82 IsTrusted: false,83 IconURL: "https://nowhere.com/img",84 Homepage: "https://nowhere.com",85 Description: "test",86 CallbackUrls: []string{"https://callback.com"},87 }88 oapp, _ = AdminClient.CreateOAuthApp(oapp)89 oapp.Name = "oapp_update"90 oapp.IsTrusted = true91 oapp.IconURL = "https://nowhere.com/img_update"92 oapp.Homepage = "https://nowhere_update.com"93 oapp.Description = "test_update"94 oapp.CallbackUrls = []string{"https://callback_update.com", "https://another_callback.com"}95 updatedApp, resp := AdminClient.UpdateOAuthApp(oapp)96 CheckNoError(t, resp)97 if updatedApp.Id != oapp.Id {98 t.Fatal("Id should have not updated")99 }100 if updatedApp.CreatorId != oapp.CreatorId {101 t.Fatal("CreatorId should have not updated")102 }103 if updatedApp.CreateAt != oapp.CreateAt {104 t.Fatal("CreateAt should have not updated")105 }106 if updatedApp.UpdateAt == oapp.UpdateAt {107 t.Fatal("UpdateAt should have updated")108 }109 if updatedApp.ClientSecret != oapp.ClientSecret {110 t.Fatal("ClientSecret should have not updated")111 }112 if updatedApp.Name != oapp.Name {113 t.Fatal("Name should have updated")114 }115 if updatedApp.Description != oapp.Description {116 t.Fatal("Description should have updated")117 }118 if updatedApp.IconURL != oapp.IconURL {119 t.Fatal("IconURL should have updated")120 }121 if len(updatedApp.CallbackUrls) == len(oapp.CallbackUrls) {122 for i, callbackUrl := range updatedApp.CallbackUrls {123 if callbackUrl != oapp.CallbackUrls[i] {124 t.Fatal("Description should have updated")125 }126 }127 }128 if updatedApp.Homepage != oapp.Homepage {129 t.Fatal("Homepage should have updated")130 }131 if updatedApp.IsTrusted != oapp.IsTrusted {132 t.Fatal("IsTrusted should have updated")133 }134 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })135 utils.SetDefaultRolesBasedOnConfig()136 _, resp = Client.UpdateOAuthApp(oapp)137 CheckForbiddenStatus(t, resp)138 oapp.Id = "zhk9d1ggatrqz236c7h87im7bc"139 _, resp = AdminClient.UpdateOAuthApp(oapp)140 CheckNotFoundStatus(t, resp)141 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })142 _, resp = AdminClient.UpdateOAuthApp(oapp)143 CheckNotImplementedStatus(t, resp)144 Client.Logout()145 _, resp = Client.UpdateOAuthApp(oapp)146 CheckUnauthorizedStatus(t, resp)147 oapp.Id = "junk"148 _, resp = AdminClient.UpdateOAuthApp(oapp)149 CheckBadRequestStatus(t, resp)150}151func TestGetOAuthApps(t *testing.T) {152 th := Setup().InitBasic().InitSystemAdmin()153 defer th.TearDown()154 Client := th.Client155 AdminClient := th.SystemAdminClient156 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider157 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations158 defer func() {159 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })160 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })161 }()162 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })163 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })164 utils.SetDefaultRolesBasedOnConfig()165 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}166 rapp, resp := AdminClient.CreateOAuthApp(oapp)167 CheckNoError(t, resp)168 oapp.Name = GenerateTestAppName()169 rapp2, resp := Client.CreateOAuthApp(oapp)170 CheckNoError(t, resp)171 apps, resp := AdminClient.GetOAuthApps(0, 1000)172 CheckNoError(t, resp)173 found1 := false174 found2 := false175 for _, a := range apps {176 if a.Id == rapp.Id {177 found1 = true178 }179 if a.Id == rapp2.Id {180 found2 = true181 }182 }183 if !found1 || !found2 {184 t.Fatal("missing oauth app")185 }186 apps, resp = AdminClient.GetOAuthApps(1, 1)187 CheckNoError(t, resp)188 if len(apps) != 1 {189 t.Fatal("paging failed")190 }191 apps, resp = Client.GetOAuthApps(0, 1000)192 CheckNoError(t, resp)193 if len(apps) != 1 && apps[0].Id != rapp2.Id {194 t.Fatal("wrong apps returned")195 }196 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })197 utils.SetDefaultRolesBasedOnConfig()198 _, resp = Client.GetOAuthApps(0, 1000)199 CheckForbiddenStatus(t, resp)200 Client.Logout()201 _, resp = Client.GetOAuthApps(0, 1000)202 CheckUnauthorizedStatus(t, resp)203 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })204 _, resp = AdminClient.GetOAuthApps(0, 1000)205 CheckNotImplementedStatus(t, resp)206}207func TestGetOAuthApp(t *testing.T) {208 th := Setup().InitBasic().InitSystemAdmin()209 defer th.TearDown()210 Client := th.Client211 AdminClient := th.SystemAdminClient212 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider213 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations214 defer func() {215 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })216 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })217 }()218 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })219 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })220 utils.SetDefaultRolesBasedOnConfig()221 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}222 rapp, resp := AdminClient.CreateOAuthApp(oapp)223 CheckNoError(t, resp)224 oapp.Name = GenerateTestAppName()225 rapp2, resp := Client.CreateOAuthApp(oapp)226 CheckNoError(t, resp)227 rrapp, resp := AdminClient.GetOAuthApp(rapp.Id)228 CheckNoError(t, resp)229 if rapp.Id != rrapp.Id {230 t.Fatal("wrong app")231 }232 if rrapp.ClientSecret == "" {233 t.Fatal("should not be sanitized")234 }235 rrapp2, resp := AdminClient.GetOAuthApp(rapp2.Id)236 CheckNoError(t, resp)237 if rapp2.Id != rrapp2.Id {238 t.Fatal("wrong app")239 }240 if rrapp2.ClientSecret == "" {241 t.Fatal("should not be sanitized")242 }243 _, resp = Client.GetOAuthApp(rapp2.Id)244 CheckNoError(t, resp)245 _, resp = Client.GetOAuthApp(rapp.Id)246 CheckForbiddenStatus(t, resp)247 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })248 utils.SetDefaultRolesBasedOnConfig()249 _, resp = Client.GetOAuthApp(rapp2.Id)250 CheckForbiddenStatus(t, resp)251 Client.Logout()252 _, resp = Client.GetOAuthApp(rapp2.Id)253 CheckUnauthorizedStatus(t, resp)254 _, resp = AdminClient.GetOAuthApp("junk")255 CheckBadRequestStatus(t, resp)256 _, resp = AdminClient.GetOAuthApp(model.NewId())257 CheckNotFoundStatus(t, resp)258 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })259 _, resp = AdminClient.GetOAuthApp(rapp.Id)260 CheckNotImplementedStatus(t, resp)261}262func TestGetOAuthAppInfo(t *testing.T) {263 th := Setup().InitBasic().InitSystemAdmin()264 defer th.TearDown()265 Client := th.Client266 AdminClient := th.SystemAdminClient267 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider268 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations269 defer func() {270 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })271 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })272 }()273 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })274 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })275 utils.SetDefaultRolesBasedOnConfig()276 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}277 rapp, resp := AdminClient.CreateOAuthApp(oapp)278 CheckNoError(t, resp)279 oapp.Name = GenerateTestAppName()280 rapp2, resp := Client.CreateOAuthApp(oapp)281 CheckNoError(t, resp)282 rrapp, resp := AdminClient.GetOAuthAppInfo(rapp.Id)283 CheckNoError(t, resp)284 if rapp.Id != rrapp.Id {285 t.Fatal("wrong app")286 }287 if rrapp.ClientSecret != "" {288 t.Fatal("should be sanitized")289 }290 rrapp2, resp := AdminClient.GetOAuthAppInfo(rapp2.Id)291 CheckNoError(t, resp)292 if rapp2.Id != rrapp2.Id {293 t.Fatal("wrong app")294 }295 if rrapp2.ClientSecret != "" {296 t.Fatal("should be sanitized")297 }298 _, resp = Client.GetOAuthAppInfo(rapp2.Id)299 CheckNoError(t, resp)300 _, resp = Client.GetOAuthAppInfo(rapp.Id)301 CheckNoError(t, resp)302 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })303 utils.SetDefaultRolesBasedOnConfig()304 _, resp = Client.GetOAuthAppInfo(rapp2.Id)305 CheckNoError(t, resp)306 Client.Logout()307 _, resp = Client.GetOAuthAppInfo(rapp2.Id)308 CheckUnauthorizedStatus(t, resp)309 _, resp = AdminClient.GetOAuthAppInfo("junk")310 CheckBadRequestStatus(t, resp)311 _, resp = AdminClient.GetOAuthAppInfo(model.NewId())312 CheckNotFoundStatus(t, resp)313 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })314 _, resp = AdminClient.GetOAuthAppInfo(rapp.Id)315 CheckNotImplementedStatus(t, resp)316}317func TestDeleteOAuthApp(t *testing.T) {318 th := Setup().InitBasic().InitSystemAdmin()319 defer th.TearDown()320 Client := th.Client321 AdminClient := th.SystemAdminClient322 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider323 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations324 defer func() {325 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })326 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })327 }()328 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })329 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })330 utils.SetDefaultRolesBasedOnConfig()331 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}332 rapp, resp := AdminClient.CreateOAuthApp(oapp)333 CheckNoError(t, resp)334 oapp.Name = GenerateTestAppName()335 rapp2, resp := Client.CreateOAuthApp(oapp)336 CheckNoError(t, resp)337 pass, resp := AdminClient.DeleteOAuthApp(rapp.Id)338 CheckNoError(t, resp)339 if !pass {340 t.Fatal("should have passed")341 }342 _, resp = AdminClient.DeleteOAuthApp(rapp2.Id)343 CheckNoError(t, resp)344 rapp, resp = AdminClient.CreateOAuthApp(oapp)345 CheckNoError(t, resp)346 oapp.Name = GenerateTestAppName()347 rapp2, resp = Client.CreateOAuthApp(oapp)348 CheckNoError(t, resp)349 _, resp = Client.DeleteOAuthApp(rapp.Id)350 CheckForbiddenStatus(t, resp)351 _, resp = Client.DeleteOAuthApp(rapp2.Id)352 CheckNoError(t, resp)353 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })354 utils.SetDefaultRolesBasedOnConfig()355 _, resp = Client.DeleteOAuthApp(rapp.Id)356 CheckForbiddenStatus(t, resp)357 Client.Logout()358 _, resp = Client.DeleteOAuthApp(rapp.Id)359 CheckUnauthorizedStatus(t, resp)360 _, resp = AdminClient.DeleteOAuthApp("junk")361 CheckBadRequestStatus(t, resp)362 _, resp = AdminClient.DeleteOAuthApp(model.NewId())363 CheckNotFoundStatus(t, resp)364 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })365 _, resp = AdminClient.DeleteOAuthApp(rapp.Id)366 CheckNotImplementedStatus(t, resp)367}368func TestRegenerateOAuthAppSecret(t *testing.T) {369 th := Setup().InitBasic().InitSystemAdmin()370 defer th.TearDown()371 Client := th.Client372 AdminClient := th.SystemAdminClient373 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider374 adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations375 defer func() {376 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })377 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })378 }()379 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })380 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })381 utils.SetDefaultRolesBasedOnConfig()382 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}383 rapp, resp := AdminClient.CreateOAuthApp(oapp)384 CheckNoError(t, resp)385 oapp.Name = GenerateTestAppName()386 rapp2, resp := Client.CreateOAuthApp(oapp)387 CheckNoError(t, resp)388 rrapp, resp := AdminClient.RegenerateOAuthAppSecret(rapp.Id)389 CheckNoError(t, resp)390 if rrapp.Id != rapp.Id {391 t.Fatal("wrong app")392 }393 if rrapp.ClientSecret == rapp.ClientSecret {394 t.Fatal("secret didn't change")395 }396 _, resp = AdminClient.RegenerateOAuthAppSecret(rapp2.Id)397 CheckNoError(t, resp)398 rapp, resp = AdminClient.CreateOAuthApp(oapp)399 CheckNoError(t, resp)400 oapp.Name = GenerateTestAppName()401 rapp2, resp = Client.CreateOAuthApp(oapp)402 CheckNoError(t, resp)403 _, resp = Client.RegenerateOAuthAppSecret(rapp.Id)404 CheckForbiddenStatus(t, resp)405 _, resp = Client.RegenerateOAuthAppSecret(rapp2.Id)406 CheckNoError(t, resp)407 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })408 utils.SetDefaultRolesBasedOnConfig()409 _, resp = Client.RegenerateOAuthAppSecret(rapp.Id)410 CheckForbiddenStatus(t, resp)411 Client.Logout()412 _, resp = Client.RegenerateOAuthAppSecret(rapp.Id)413 CheckUnauthorizedStatus(t, resp)414 _, resp = AdminClient.RegenerateOAuthAppSecret("junk")415 CheckBadRequestStatus(t, resp)416 _, resp = AdminClient.RegenerateOAuthAppSecret(model.NewId())417 CheckNotFoundStatus(t, resp)418 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })419 _, resp = AdminClient.RegenerateOAuthAppSecret(rapp.Id)420 CheckNotImplementedStatus(t, resp)421}422func TestGetAuthorizedOAuthAppsForUser(t *testing.T) {423 th := Setup().InitBasic().InitSystemAdmin()424 defer th.TearDown()425 Client := th.Client426 AdminClient := th.SystemAdminClient427 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider428 defer func() {429 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })430 }()431 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })432 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}433 rapp, resp := AdminClient.CreateOAuthApp(oapp)434 CheckNoError(t, resp)435 authRequest := &model.AuthorizeRequest{436 ResponseType: model.AUTHCODE_RESPONSE_TYPE,437 ClientId: rapp.Id,438 RedirectUri: rapp.CallbackUrls[0],439 Scope: "",440 State: "123",441 }442 _, resp = Client.AuthorizeOAuthApp(authRequest)443 CheckNoError(t, resp)444 apps, resp := Client.GetAuthorizedOAuthAppsForUser(th.BasicUser.Id, 0, 1000)445 CheckNoError(t, resp)446 found := false447 for _, a := range apps {448 if a.Id == rapp.Id {449 found = true450 }451 if a.ClientSecret != "" {452 t.Fatal("not sanitized")453 }454 }455 if !found {456 t.Fatal("missing app")457 }458 _, resp = Client.GetAuthorizedOAuthAppsForUser(th.BasicUser2.Id, 0, 1000)459 CheckForbiddenStatus(t, resp)460 _, resp = Client.GetAuthorizedOAuthAppsForUser("junk", 0, 1000)461 CheckBadRequestStatus(t, resp)462 Client.Logout()463 _, resp = Client.GetAuthorizedOAuthAppsForUser(th.BasicUser.Id, 0, 1000)464 CheckUnauthorizedStatus(t, resp)465 _, resp = AdminClient.GetAuthorizedOAuthAppsForUser(th.BasicUser.Id, 0, 1000)466 CheckNoError(t, resp)467}468func TestAuthorizeOAuthApp(t *testing.T) {469 th := Setup().InitBasic().InitSystemAdmin()470 defer th.TearDown()471 Client := th.Client472 AdminClient := th.SystemAdminClient473 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider474 defer func() {475 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })476 }()477 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })478 utils.SetDefaultRolesBasedOnConfig()479 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}480 rapp, resp := AdminClient.CreateOAuthApp(oapp)481 CheckNoError(t, resp)482 authRequest := &model.AuthorizeRequest{483 ResponseType: model.AUTHCODE_RESPONSE_TYPE,484 ClientId: rapp.Id,485 RedirectUri: rapp.CallbackUrls[0],486 Scope: "",487 State: "123",488 }489 ruri, resp := Client.AuthorizeOAuthApp(authRequest)490 CheckNoError(t, resp)491 if len(ruri) == 0 {492 t.Fatal("redirect url should be set")493 }494 ru, _ := url.Parse(ruri)495 if ru == nil {496 t.Fatal("redirect url unparseable")497 } else {498 if len(ru.Query().Get("code")) == 0 {499 t.Fatal("authorization code not returned")500 }501 if ru.Query().Get("state") != authRequest.State {502 t.Fatal("returned state doesn't match")503 }504 }505 authRequest.RedirectUri = ""506 _, resp = Client.AuthorizeOAuthApp(authRequest)507 CheckBadRequestStatus(t, resp)508 authRequest.RedirectUri = "http://somewhereelse.com"509 _, resp = Client.AuthorizeOAuthApp(authRequest)510 CheckBadRequestStatus(t, resp)511 authRequest.RedirectUri = rapp.CallbackUrls[0]512 authRequest.ResponseType = ""513 _, resp = Client.AuthorizeOAuthApp(authRequest)514 CheckBadRequestStatus(t, resp)515 authRequest.ResponseType = model.AUTHCODE_RESPONSE_TYPE516 authRequest.ClientId = ""517 _, resp = Client.AuthorizeOAuthApp(authRequest)518 CheckBadRequestStatus(t, resp)519 authRequest.ClientId = model.NewId()520 _, resp = Client.AuthorizeOAuthApp(authRequest)521 CheckNotFoundStatus(t, resp)522}523func TestDeauthorizeOAuthApp(t *testing.T) {524 th := Setup().InitBasic().InitSystemAdmin()525 defer th.TearDown()526 Client := th.Client527 AdminClient := th.SystemAdminClient528 enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider529 defer func() {530 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })531 }()532 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })533 oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}534 rapp, resp := AdminClient.CreateOAuthApp(oapp)535 CheckNoError(t, resp)536 authRequest := &model.AuthorizeRequest{537 ResponseType: model.AUTHCODE_RESPONSE_TYPE,538 ClientId: rapp.Id,539 RedirectUri: rapp.CallbackUrls[0],540 Scope: "",541 State: "123",542 }543 _, resp = Client.AuthorizeOAuthApp(authRequest)544 CheckNoError(t, resp)545 pass, resp := Client.DeauthorizeOAuthApp(rapp.Id)546 CheckNoError(t, resp)...

Full Screen

Full Screen

updateconfig.go

Source:updateconfig.go Github

copy

Full Screen

...20 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"21 watch "k8s.io/apimachinery/pkg/watch"22 rest "k8s.io/client-go/rest"23)24// UpdateConfigsGetter has a method to return a UpdateConfigInterface.25// A group's client should implement this interface.26type UpdateConfigsGetter interface {27 UpdateConfigs() UpdateConfigInterface28}29// UpdateConfigInterface has methods to work with UpdateConfig resources.30type UpdateConfigInterface interface {31 Create(ctx context.Context, updateConfig *v1beta2.UpdateConfig, opts v1.CreateOptions) (*v1beta2.UpdateConfig, error)32 Update(ctx context.Context, updateConfig *v1beta2.UpdateConfig, opts v1.UpdateOptions) (*v1beta2.UpdateConfig, error)33 Delete(ctx context.Context, name string, opts v1.DeleteOptions) error34 Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta2.UpdateConfig, error)35 List(ctx context.Context, opts v1.ListOptions) (*v1beta2.UpdateConfigList, error)36 Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)37 UpdateConfigExpansion38}39// updateConfigs implements UpdateConfigInterface40type updateConfigs struct {41 client rest.Interface42}43// newUpdateConfigs returns a UpdateConfigs44func newUpdateConfigs(c *AutopilotV1beta2Client) *updateConfigs {45 return &updateConfigs{46 client: c.RESTClient(),47 }48}49// Get takes name of the updateConfig, and returns the corresponding updateConfig object, and an error if there is any.50func (c *updateConfigs) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta2.UpdateConfig, err error) {51 result = &v1beta2.UpdateConfig{}52 err = c.client.Get().53 Resource("updateconfigs").54 Name(name).55 VersionedParams(&options, scheme.ParameterCodec).56 Do(ctx).57 Into(result)58 return59}60// List takes label and field selectors, and returns the list of UpdateConfigs that match those selectors.61func (c *updateConfigs) List(ctx context.Context, opts v1.ListOptions) (result *v1beta2.UpdateConfigList, err error) {62 var timeout time.Duration63 if opts.TimeoutSeconds != nil {64 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second65 }66 result = &v1beta2.UpdateConfigList{}67 err = c.client.Get().68 Resource("updateconfigs").69 VersionedParams(&opts, scheme.ParameterCodec).70 Timeout(timeout).71 Do(ctx).72 Into(result)73 return74}75// Watch returns a watch.Interface that watches the requested updateConfigs.76func (c *updateConfigs) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {77 var timeout time.Duration78 if opts.TimeoutSeconds != nil {79 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second80 }81 opts.Watch = true82 return c.client.Get().83 Resource("updateconfigs").84 VersionedParams(&opts, scheme.ParameterCodec).85 Timeout(timeout).86 Watch(ctx)87}88// Create takes the representation of a updateConfig and creates it. Returns the server's representation of the updateConfig, and an error, if there is any.89func (c *updateConfigs) Create(ctx context.Context, updateConfig *v1beta2.UpdateConfig, opts v1.CreateOptions) (result *v1beta2.UpdateConfig, err error) {90 result = &v1beta2.UpdateConfig{}91 err = c.client.Post().92 Resource("updateconfigs").93 VersionedParams(&opts, scheme.ParameterCodec).94 Body(updateConfig).95 Do(ctx).96 Into(result)97 return98}99// Update takes the representation of a updateConfig and updates it. Returns the server's representation of the updateConfig, and an error, if there is any.100func (c *updateConfigs) Update(ctx context.Context, updateConfig *v1beta2.UpdateConfig, opts v1.UpdateOptions) (result *v1beta2.UpdateConfig, err error) {101 result = &v1beta2.UpdateConfig{}102 err = c.client.Put().103 Resource("updateconfigs").104 Name(updateConfig.Name).105 VersionedParams(&opts, scheme.ParameterCodec).106 Body(updateConfig).107 Do(ctx).108 Into(result)109 return110}111// Delete takes name of the updateConfig and deletes it. Returns an error if one occurs.112func (c *updateConfigs) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {113 return c.client.Delete().114 Resource("updateconfigs").115 Name(name)....

Full Screen

Full Screen

UpdateConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c, err := client.NewHTTPClient(client.HTTPConfig{4 })5 if err != nil {6 log.Fatal(err)7 }8 bp, err := client.NewBatchPoints(client.BatchPointsConfig{9 })10 if err != nil {11 log.Fatal(err)12 }13 tags := map[string]string{"cpu": "cpu-total"}14 fields := map[string]interface{}{15 }16 pt, err := client.NewPoint("cpu_usage_idle", tags, fields, time.Now())17 if err != nil {18 log.Fatal(err)19 }20 bp.AddPoint(pt)21 c.Write(bp)22 newConfig := client.HTTPConfig{23 }24 c.UpdateConfig(newConfig)25 c.Write(bp)26}

Full Screen

Full Screen

UpdateConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client, err := clientv3.New(clientv3.Config{4 Endpoints: []string{"localhost:2379"},5 })6 if err != nil {7 log.Fatal(err)8 }9 defer client.Close()10 ctx, cancel := context.WithTimeout(context.Background(), time.Second)11 _, err = client.UpdateConfig(ctx, "localhost:2379", clientv3.Config{Endpoints: []string{"localhost:2379"}})12 if err != nil {13 log.Fatal(err)14 }15 defer cancel()16}

Full Screen

Full Screen

UpdateConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := context.Background()4 client, err := bookshelf.NewClient(ctx)5 if err != nil {6 log.Fatalf("Failed to create client: %v", err)7 }8 if err := client.UpdateConfig(ctx, "my-project"); err != nil {9 log.Fatalf("Failed to update config: %v", err)10 }11 fmt.Println("Updated config.")12}13import (14func main() {15 ctx := context.Background()16 client, err := bookshelf.NewClient(ctx)17 if err != nil {18 log.Fatalf("Failed to create client: %v", err)19 }20 if err := client.UpdateConfig(ctx, "my-project"); err != nil {21 log.Fatalf("Failed to update config: %v", err)22 }23 fmt.Println("Updated config.")24}25import (26func main() {27 ctx := context.Background()28 client, err := bookshelf.NewClient(ctx)29 if err != nil {30 log.Fatalf("Failed to create client: %v", err)31 }32 if err := client.UpdateConfig(ctx, "my-project"); err != nil {33 log.Fatalf("Failed to update config: %v", err)34 }35 fmt.Println("Updated config.")36}37import (38func main() {39 ctx := context.Background()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful