[ISSUE-67901957] 404 for no resources
diff --git a/accessEntity/api.go b/accessEntity/api.go index eb4561a..f89c725 100644 --- a/accessEntity/api.go +++ b/accessEntity/api.go
@@ -80,6 +80,12 @@ StatusCode: http.StatusBadRequest, } + ErrNotFound = &common.ErrorResponse{ + ResponseCode: strconv.Itoa(NOT_FOUND), + ResponseMessage: "Resource Not Found", + StatusCode: http.StatusNotFound, + } + IdentifierTree = map[string]map[string][]string{ EndpointApiProduct: { IdentifierApiProductName: {}, @@ -116,6 +122,7 @@ INVALID_PARAMETERS = iota DB_ERROR DATA_ERROR + NOT_FOUND ) type ApiManager struct { @@ -255,10 +262,7 @@ } if len(devs) == 0 { - return &CompanyDevelopersSuccessResponse{ - CompanyDevelopers: nil, - Organization: org, - }, nil + return nil, ErrNotFound } var details []*CompanyDeveloperDetails @@ -298,10 +302,7 @@ } if len(devs) == 0 { - return &DeveloperSuccessResponse{ - Developer: nil, - Organization: org, - }, nil + return nil, ErrNotFound } dev := &devs[0] @@ -339,10 +340,7 @@ } if len(coms) == 0 { - return &CompanySuccessResponse{ - Company: nil, - Organization: org, - }, nil + return nil, ErrNotFound } com := &coms[0] @@ -376,10 +374,7 @@ var attrs []common.Attribute if len(prods) == 0 { - return &ApiProductSuccessResponse{ - ApiProduct: nil, - Organization: org, - }, nil + return nil, ErrNotFound } prod := &prods[0] attrs = a.DbMan.GetKmsAttributes(prod.TenantId, prod.Id)[prod.Id] @@ -412,10 +407,7 @@ } if len(appCreds) == 0 { - return &AppCredentialSuccessResponse{ - AppCredential: nil, - Organization: org, - }, nil + return nil, ErrNotFound } appCred := &appCreds[0] attrs := a.DbMan.GetKmsAttributes(appCred.TenantId, appCred.Id)[appCred.Id] @@ -447,7 +439,7 @@ } cks := makeConsumerKeyStatusDetails(app, cd, devStatus) //TODO: redirectUris - details := makeAppCredentialDetails(appCred, cks, []string{}, attrs) + details := makeAppCredentialDetails(appCred, cks, []string{app.CallbackUrl}, attrs) return &AppCredentialSuccessResponse{ AppCredential: details, Organization: org, @@ -473,10 +465,7 @@ var attrs []common.Attribute if len(apps) == 0 { - return &AppSuccessResponse{ - App: nil, - Organization: org, - }, nil + return nil, ErrNotFound } app = &apps[0]
diff --git a/accessEntity/data.go b/accessEntity/data.go index 70b3ca9..e709445 100644 --- a/accessEntity/data.go +++ b/accessEntity/data.go
@@ -316,7 +316,7 @@ ), cols..., ) + " AND ap.tenant_id IN " + sql_select_tenant_org - log.Debugf("getApiProductsByAppId: %v", query) + //log.Debugf("getApiProductsByAppId: %v", query) err = d.GetDb().QueryStructs(&apiProducts, query, org) return } @@ -330,7 +330,7 @@ ), cols..., ) + " AND ap.tenant_id IN " + sql_select_tenant_org - log.Debugf("getApiProductsByConsumerKey: %v", query) + //log.Debugf("getApiProductsByConsumerKey: %v", query) err = d.GetDb().QueryStructs(&apiProducts, query, org) return } @@ -377,7 +377,7 @@ ), cols..., ) + " AND ap.tenant_id IN " + sql_select_tenant_org - log.Debugf("getApiProductsByAppName: %v", query) + //log.Debugf("getApiProductsByAppName: %v", query) err = d.GetDb().QueryStructs(&apiProducts, query, org) return } @@ -388,7 +388,7 @@ "'"+id+"'", cols..., ) + " AND a.tenant_id IN " + sql_select_tenant_org - log.Debugf("getAppByAppId: %v", query) + //log.Debugf("getAppByAppId: %v", query) err = d.GetDb().QueryStructs(&apps, query, org) return } @@ -428,7 +428,7 @@ ) } query += " AND a.tenant_id IN " + sql_select_tenant_org - log.Debugf("getAppByAppName: %v", query) + //log.Debugf("getAppByAppName: %v", query) err = d.GetDb().QueryStructs(&apps, query, org) return } @@ -442,7 +442,7 @@ ), cols..., ) + " AND a.tenant_id IN " + sql_select_tenant_org - log.Debugf("getAppByConsumerKey: %v", query) + //log.Debugf("getAppByConsumerKey: %v", query) err = d.GetDb().QueryStructs(&apps, query, org) return } @@ -453,7 +453,7 @@ "'"+consumerKey+"'", cols..., ) + " AND ac.tenant_id IN " + sql_select_tenant_org - log.Debugf("getAppCredentialByConsumerKey: %v", query) + //log.Debugf("getAppCredentialByConsumerKey: %v", query) err = d.GetDb().QueryStructs(&appCredentials, query, org) return } @@ -467,7 +467,7 @@ ), cols..., ) + " AND com.tenant_id IN " + sql_select_tenant_org - log.Debugf("getCompanyByAppId: %v", query) + //log.Debugf("getCompanyByAppId: %v", query) err = d.GetDb().QueryStructs(&companies, query, org) return } @@ -478,7 +478,7 @@ "'"+name+"'", cols..., ) + " AND com.tenant_id IN " + sql_select_tenant_org - log.Debugf("getCompanyByName: %v", query) + //log.Debugf("getCompanyByName: %v", query) err = d.GetDb().QueryStructs(&companies, query, org) return } @@ -495,7 +495,7 @@ ), cols..., ) + " AND com.tenant_id IN " + sql_select_tenant_org - log.Debugf("getCompanyByConsumerKey: %v", query) + //log.Debugf("getCompanyByConsumerKey: %v", query) err = d.GetDb().QueryStructs(&companies, query, org) return } @@ -509,7 +509,7 @@ ), cols..., ) + " AND cd.tenant_id IN " + sql_select_tenant_org - log.Debugf("getCompanyDeveloperByComName: %v", query) + //log.Debugf("getCompanyDeveloperByComName: %v", query) err = d.GetDb().QueryStructs(&companyDevelopers, query, org) return } @@ -523,7 +523,7 @@ ), cols..., ) + " AND dev.tenant_id IN " + sql_select_tenant_org - log.Debugf("getDeveloperByAppId: %v", query) + //log.Debugf("getDeveloperByAppId: %v", query) err = d.GetDb().QueryStructs(&developers, query, org) return } @@ -540,7 +540,7 @@ ), cols..., ) + " AND dev.tenant_id IN " + sql_select_tenant_org - log.Debugf("getDeveloperByConsumerKey: %v", query) + //log.Debugf("getDeveloperByConsumerKey: %v", query) err = d.GetDb().QueryStructs(&developers, query, org) return } @@ -551,7 +551,7 @@ "'"+email+"'", cols..., ) + " AND dev.tenant_id IN " + sql_select_tenant_org - log.Debugf("getDeveloperByEmail: %v", query) + //log.Debugf("getDeveloperByEmail: %v", query) err = d.GetDb().QueryStructs(&developers, query, org) return } @@ -562,7 +562,7 @@ "'"+id+"'", cols..., ) + " AND dev.tenant_id IN " + sql_select_tenant_org - log.Debugf("getDeveloperById: %v", query) + //log.Debugf("getDeveloperById: %v", query) err = d.GetDb().QueryStructs(&developers, query, org) return } @@ -711,7 +711,7 @@ } func filterApiProductsByResource(apiProducts []common.ApiProduct, resource string) []common.ApiProduct { - log.Debugf("Before filter: %v", apiProducts) + //log.Debugf("Before filter: %v", apiProducts) var prods []common.ApiProduct for _, prod := range apiProducts { resources := common.JsonToStringArray(prod.ApiResources) @@ -719,7 +719,7 @@ prods = append(prods, prod) } } - log.Debugf("After filter: %v", prods) + //log.Debugf("After filter: %v", prods) return prods }
diff --git a/accessEntity/mock_test.go b/accessEntity/mock_test.go new file mode 100644 index 0000000..ff22487 --- /dev/null +++ b/accessEntity/mock_test.go
@@ -0,0 +1,87 @@ +// Copyright 2017 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package accessEntity + +import "github.com/apid/apidVerifyApiKey/common" + +type DummyDbMan struct { + apiProducts []common.ApiProduct + apps []common.App + companies []common.Company + companyDevelopers []common.CompanyDeveloper + appCredentials []common.AppCredential + developers []common.Developer + apiProductNames []string + appNames []string + comNames []string + email string + status string + attrs map[string][]common.Attribute + err error +} + +func (d *DummyDbMan) SetDbVersion(string) { + +} +func (d *DummyDbMan) GetDbVersion() string { + return "" +} + +func (d *DummyDbMan) GetKmsAttributes(tenantId string, entities ...string) map[string][]common.Attribute { + return d.attrs +} + +func (d *DummyDbMan) GetApiProducts(org, priKey, priVal, secKey, secVal string) (apiProducts []common.ApiProduct, err error) { + return d.apiProducts, d.err +} + +func (d *DummyDbMan) GetApps(org, priKey, priVal, secKey, secVal string) (apps []common.App, err error) { + return d.apps, d.err +} + +func (d *DummyDbMan) GetCompanies(org, priKey, priVal, secKey, secVal string) (companies []common.Company, err error) { + return d.companies, d.err +} + +func (d *DummyDbMan) GetCompanyDevelopers(org, priKey, priVal, secKey, secVal string) (companyDevelopers []common.CompanyDeveloper, err error) { + return d.companyDevelopers, d.err +} + +func (d *DummyDbMan) GetAppCredentials(org, priKey, priVal, secKey, secVal string) (appCredentials []common.AppCredential, err error) { + return d.appCredentials, d.err +} + +func (d *DummyDbMan) GetDevelopers(org, priKey, priVal, secKey, secVal string) (developers []common.Developer, err error) { + return d.developers, d.err +} + +func (d *DummyDbMan) GetApiProductNames(id string, idType string) ([]string, error) { + return d.apiProductNames, d.err +} + +func (d *DummyDbMan) GetAppNames(id string, idType string) ([]string, error) { + return d.appNames, d.err +} + +func (d *DummyDbMan) GetComNames(id string, idType string) ([]string, error) { + return d.comNames, d.err +} + +func (d *DummyDbMan) GetDevEmailByDevId(devId string) (string, error) { + return d.email, d.err +} + +func (d *DummyDbMan) GetStatus(id, t string) (string, error) { + return d.status, d.err +}
diff --git a/common/interfaces.go b/common/interfaces.go index dda46f3..a14184b 100644 --- a/common/interfaces.go +++ b/common/interfaces.go
@@ -13,9 +13,6 @@ // limitations under the License. package common -import ( - "github.com/apid/apid-core" -) type ApiManagerInterface interface { InitAPI() @@ -23,7 +20,6 @@ type DbManagerInterface interface { SetDbVersion(string) - GetDb() apid.DB GetDbVersion() string GetKmsAttributes(tenantId string, entities ...string) map[string][]Attribute }