Skip to content

Conversation

@Ninja243
Copy link
Contributor

Adds tests for the IAM package

token.isValid() more strict, removed more common.ThrowError calls
@github-actions
Copy link

github-actions bot commented Oct 15, 2025

Code Coverage Report

Total Coverage: 25.6%

Details
otc-auth/accesstoken/accesstoken.go:20:		CreateAccessToken				0.0%
otc-auth/accesstoken/accesstoken.go:37:		makeAccessFile					0.0%
otc-auth/accesstoken/accesstoken.go:78:		CreateTemporaryAccessToken			0.0%
otc-auth/accesstoken/accesstoken.go:89:		ListAccessToken					0.0%
otc-auth/accesstoken/accesstoken.go:105:	getTempAccessTokenFromServiceProvider		0.0%
otc-auth/accesstoken/accesstoken.go:121:	getAccessTokenFromServiceProvider		0.0%
otc-auth/accesstoken/accesstoken.go:145:	handlePotentialLimitError			0.0%
otc-auth/accesstoken/accesstoken.go:168:	conditionallyReplaceAccessTokens		0.0%
otc-auth/accesstoken/accesstoken.go:192:	DeleteAccessToken				0.0%
otc-auth/accesstoken/accesstoken.go:200:	getIdentityServiceClient			0.0%
otc-auth/cce/cce.go:27:				GetClusterNames					0.0%
otc-auth/cce/cce.go:50:				GetKubeConfig					0.0%
otc-auth/cce/cce.go:90:				CheckAndWarnCertsValidity			0.0%
otc-auth/cce/cce.go:124:			getAuthInfoCerts				0.0%
otc-auth/cce/cce.go:148:			getClusterCerts					0.0%
otc-auth/cce/cce.go:176:			sprintCertInfo					0.0%
otc-auth/cce/cce.go:184:			getClustersForProjectFromServiceProvider	0.0%
otc-auth/cce/cce.go:209:			getKubeConfFromServiceProvider			0.0%
otc-auth/cce/cce.go:295:			getClusterID					0.0%
otc-auth/cce/cce.go:319:			getRefreshedClusterArr				0.0%
otc-auth/cce/kube_config.go:19:			getKubeConfig					0.0%
otc-auth/cce/kube_config.go:30:			mergeKubeConfig					0.0%
otc-auth/cce/kube_config.go:45:			merge						100.0%
otc-auth/cce/kube_config.go:50:			determineTargetLocation				0.0%
otc-auth/cce/kube_config.go:62:			renameKubeconfigEntries				0.0%
otc-auth/cmd/cmd_config.go:16:			initializeConfig				0.0%
otc-auth/cmd/cmd_config.go:35:			configureCmdFlagsAgainstEnvs			0.0%
otc-auth/cmd/completion.go:89:			init						0.0%
otc-auth/cmd/documentation.go:43:		init						0.0%
otc-auth/cmd/root.go:380:			Execute						0.0%
otc-auth/cmd/root.go:391:			setupRootCmd					0.0%
otc-auth/cmd/version.go:9:			SetVersionInfo					0.0%
otc-auth/common/endpoints/endpoints.go:15:	BaseURLIam					0.0%
otc-auth/common/endpoints/endpoints.go:27:	IdentityProviders				0.0%
otc-auth/common/functions.go:14:		RemoveFromSliceAtIndex				0.0%
otc-auth/common/functions.go:19:		WriteStringToFile				0.0%
otc-auth/common/functions.go:34:		ByteSliceToIndentedJSONFormat			0.0%
otc-auth/common/functions.go:43:		DeserializeJSONForType				80.0%
otc-auth/common/functions.go:53:		ThrowError					0.0%
otc-auth/common/http_client.go:20:		NewHTTPClient					0.0%
otc-auth/common/http_client.go:33:		MakeRequest					0.0%
otc-auth/common/http_client.go:38:		NewRequest					0.0%
otc-auth/common/http_client.go:49:		GetBodyBytesFromResponse			72.7%
otc-auth/common/otc_auth_helper.go:15:		GetCloudCredentialsFromResponse			55.0%
otc-auth/common/otc_auth_helper.go:50:		ParseTime					100.0%
otc-auth/config/config.go:21:			SetCustomConfigFilePath				0.0%
otc-auth/config/config.go:25:			effectiveConfigPath				0.0%
otc-auth/config/config.go:40:			LoadCloudConfig					0.0%
otc-auth/config/config.go:60:			registerNewCloud				0.0%
otc-auth/config/config.go:83:			IsAuthenticationValid				0.0%
otc-auth/config/config.go:111:			RemoveCloudConfig				0.0%
otc-auth/config/config.go:129:			UpdateClusters					0.0%
otc-auth/config/config.go:145:			UpdateProjects					0.0%
otc-auth/config/config.go:161:			UpdateCloudConfig				0.0%
otc-auth/config/config.go:180:			GetActiveCloudConfig				0.0%
otc-auth/config/config.go:196:			OtcConfigFileExists				0.0%
otc-auth/config/config.go:209:			getOtcConfig					0.0%
otc-auth/config/config.go:235:			createConfigFileWithCloudConfig			0.0%
otc-auth/config/config.go:243:			writeOtcConfigContentToFile			0.0%
otc-auth/config/config.go:256:			readFileContent					0.0%
otc-auth/config/config.go:285:			WriteConfigFile					0.0%
otc-auth/config/config.go:303:			removeCloudConfig				0.0%
otc-auth/config/model.go:20:			ContainsCloud					100.0%
otc-auth/config/model.go:29:			RemoveCloudByNameIfExists			100.0%
otc-auth/config/model.go:37:			SetActiveByName					100.0%
otc-auth/config/model.go:47:			FindActiveCloudConfigOrNil			100.0%
otc-auth/config/model.go:61:			GetActiveCloudIndex				100.0%
otc-auth/config/model.go:70:			NumberOfActiveCloudConfigs			100.0%
otc-auth/config/model.go:96:			FindProjectByName				100.0%
otc-auth/config/model.go:105:			GetProjectByName				100.0%
otc-auth/config/model.go:115:			FindProjectIndexByName				100.0%
otc-auth/config/model.go:124:			GetProjectNames					100.0%
otc-auth/config/model.go:137:			GetClusterNames					100.0%
otc-auth/config/model.go:145:			GetClusterByName				100.0%
otc-auth/config/model.go:154:			FindClusterByName				100.0%
otc-auth/config/model.go:163:			ContainsClusterByName				100.0%
otc-auth/config/model.go:178:			IsValid						85.7%
otc-auth/config/model.go:190:			UpdateToken					100.0%
otc-auth/iam/iam.go:19:				AuthenticateAndGetUnscopedToken			0.0%
otc-auth/iam/iam.go:57:				NewGopherTokenCreator				0.0%
otc-auth/iam/iam.go:68:				NewFileConfigStore				0.0%
otc-auth/iam/iam.go:72:				GetActiveCloud					0.0%
otc-auth/iam/iam.go:76:				SaveActiveCloud					0.0%
otc-auth/iam/iam.go:80:				CreateToken					0.0%
otc-auth/iam/iam.go:93:				newIdentityV3Client				0.0%
otc-auth/iam/iam.go:106:			GetScopedToken					90.9%
otc-auth/iam/iam.go:153:			fetchNewScopedToken				100.0%
otc-auth/iam/iam.go:169:			gopherTokenToConfigToken			100.0%
otc-auth/iam/iam.go:179:			configTokenToGopherToken			100.0%
otc-auth/iam/projects.go:18:			GetProjectsInActiveCloud			0.0%
otc-auth/iam/projects.go:33:			CreateScopedTokenForEveryProject		0.0%
otc-auth/iam/projects.go:46:			getProjectsFromServiceProvider			0.0%
otc-auth/login/login.go:19:			getTokenProvider				0.0%
otc-auth/login/login.go:44:			handleSuccessfulAuthentication			0.0%
otc-auth/login/login.go:62:			AuthenticateAndGetUnscopedToken			0.0%
otc-auth/login/login.go:89:			updateOTCInfoFile				0.0%
otc-auth/main.go:31:				main						0.0%
otc-auth/oidc/oidc.go:22:			newAuthService					0.0%
otc-auth/oidc/oidc.go:30:			authenticate					100.0%
otc-auth/oidc/oidc.go:50:			AuthenticateAndGetUnscopedToken			0.0%
otc-auth/oidc/oidc.go:57:			authenticateWithServiceProvider			94.1%
otc-auth/oidc/server.go:62:			newFlowController				0.0%
otc-auth/oidc/server.go:73:			Verify						0.0%
otc-auth/oidc/server.go:77:			Authenticate					100.0%
otc-auth/oidc/server.go:119:			handleRoot					100.0%
otc-auth/oidc/server.go:137:			createAndBindListener				0.0%
otc-auth/oidc/server.go:146:			startAndListenHTTPServer			83.3%
otc-auth/oidc/server.go:161:			registerHandlers				66.7%
otc-auth/oidc/server.go:168:			handleOIDCAuth					88.9%
otc-auth/oidc/server.go:216:			newHTTPServer					100.0%
otc-auth/oidc/server.go:228:			authenticateWithIdp				0.0%
otc-auth/oidc/service_account.go:15:		createServiceAccountAuthenticateRequest		88.9%
otc-auth/oidc/service_account.go:42:		authenticateServiceAccountWithIdp		87.0%
otc-auth/openstack/openstack.go:18:		WriteOpenStackCloudsYaml			88.9%
otc-auth/openstack/openstack.go:33:		createOpenstackCloudConfig			100.0%
otc-auth/openstack/openstack.go:54:		createOpenstackCloudsYAML			66.7%
otc-auth/saml/saml.go:18:			AuthenticateAndGetUnscopedToken			0.0%
otc-auth/saml/saml.go:52:			getServiceProviderInitiatedRequest		0.0%
otc-auth/saml/saml.go:66:			authenticateWithIdp				0.0%
otc-auth/saml/saml.go:86:			validateAuthenticationWithServiceProvider	0.0%
total:						(statements)					25.6%

Comment on lines +33 to 44
func CreateScopedTokenForEveryProject(projectNames []string) error {
var tokenError error
store := NewFileConfigStore()
tc := NewGopherTokenCreator()
for _, projectName := range projectNames {
GetScopedToken(projectName)
_, err := GetScopedToken(store, tc, projectName) // Getting tokens also caches them for later use
if err != nil {
return errors.Join(tokenError, err)
}
}
return nil
}
Copy link

@krankkkk krankkkk Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems to have alot of side effects.

GetScopedToken also seems to write somewhere, which it really shouldn't do.

CreateScopedTokenForEveryProject should probably only create a map[string]string projectName -> Token and then there should be another function that actually saves these token to disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants