@@ -10,6 +10,7 @@ afterAll(() => { delete process.env.ALTIMATE_TELEMETRY_DISABLED })
1010// ---------------------------------------------------------------------------
1111
1212import * as Registry from "../../src/altimate/native/connections/registry"
13+ import { detectAuthMethod } from "../../src/altimate/native/connections/registry"
1314import * as CredentialStore from "../../src/altimate/native/connections/credential-store"
1415import { parseDbtProfiles } from "../../src/altimate/native/connections/dbt-profiles"
1516import { discoverContainers } from "../../src/altimate/native/connections/docker-discovery"
@@ -137,6 +138,69 @@ describe("CredentialStore", () => {
137138 } )
138139} )
139140
141+ // ---------------------------------------------------------------------------
142+ // detectAuthMethod
143+ // ---------------------------------------------------------------------------
144+
145+ describe ( "detectAuthMethod" , ( ) => {
146+ test ( "returns 'connection_string' for config with connection_string" , ( ) => {
147+ expect ( detectAuthMethod ( { type : "postgres" , connection_string : "postgresql://..." } as any ) ) . toBe ( "connection_string" )
148+ } )
149+
150+ test ( "returns 'key_pair' for Snowflake private_key_path" , ( ) => {
151+ expect ( detectAuthMethod ( { type : "snowflake" , private_key_path : "/path/to/key.p8" } as any ) ) . toBe ( "key_pair" )
152+ } )
153+
154+ test ( "returns 'key_pair' for camelCase privateKeyPath" , ( ) => {
155+ expect ( detectAuthMethod ( { type : "snowflake" , privateKeyPath : "/path/to/key.p8" } as any ) ) . toBe ( "key_pair" )
156+ } )
157+
158+ test ( "returns 'sso' for Snowflake externalbrowser" , ( ) => {
159+ expect ( detectAuthMethod ( { type : "snowflake" , authenticator : "EXTERNALBROWSER" } as any ) ) . toBe ( "sso" )
160+ } )
161+
162+ test ( "returns 'sso' for Okta URL authenticator" , ( ) => {
163+ expect ( detectAuthMethod ( { type : "snowflake" , authenticator : "https://myorg.okta.com" } as any ) ) . toBe ( "sso" )
164+ } )
165+
166+ test ( "returns 'oauth' for OAuth authenticator" , ( ) => {
167+ expect ( detectAuthMethod ( { type : "snowflake" , authenticator : "OAUTH" } as any ) ) . toBe ( "oauth" )
168+ } )
169+
170+ test ( "returns 'token' for access_token" , ( ) => {
171+ expect ( detectAuthMethod ( { type : "databricks" , access_token : "dapi..." } as any ) ) . toBe ( "token" )
172+ } )
173+
174+ test ( "returns 'password' for config with password" , ( ) => {
175+ expect ( detectAuthMethod ( { type : "postgres" , password : "secret" } as any ) ) . toBe ( "password" )
176+ } )
177+
178+ test ( "returns 'file' for duckdb" , ( ) => {
179+ expect ( detectAuthMethod ( { type : "duckdb" , path : "/data/my.db" } as any ) ) . toBe ( "file" )
180+ } )
181+
182+ test ( "returns 'file' for sqlite" , ( ) => {
183+ expect ( detectAuthMethod ( { type : "sqlite" , path : "/data/my.sqlite" } as any ) ) . toBe ( "file" )
184+ } )
185+
186+ test ( "returns 'connection_string' for mongodb without password" , ( ) => {
187+ expect ( detectAuthMethod ( { type : "mongodb" } as any ) ) . toBe ( "connection_string" )
188+ } )
189+
190+ test ( "returns 'password' for mongo with password" , ( ) => {
191+ expect ( detectAuthMethod ( { type : "mongo" , password : "secret" } as any ) ) . toBe ( "password" )
192+ } )
193+
194+ test ( "returns 'unknown' for null/undefined" , ( ) => {
195+ expect ( detectAuthMethod ( null ) ) . toBe ( "unknown" )
196+ expect ( detectAuthMethod ( undefined ) ) . toBe ( "unknown" )
197+ } )
198+
199+ test ( "returns 'unknown' for empty config with no identifiable auth" , ( ) => {
200+ expect ( detectAuthMethod ( { type : "postgres" } as any ) ) . toBe ( "unknown" )
201+ } )
202+ } )
203+
140204// ---------------------------------------------------------------------------
141205// dbt profiles parser
142206// ---------------------------------------------------------------------------
0 commit comments