Repository: prisma/prisma
File: packages/adapter-mssql/src/connection-string.test.ts (TypeScript)

Code before:

    it('should handle connection string with malformed key-value pairs', () => {
      const connectionString = 'sqlserver://localhost;database=testdb;=value;key=;='
      const config = parseConnectionString(connectionString)

      expect(config.server).toBe('localhost')
      expect(config.database).toBe('testdb')
      // Should ignore malformed pairs
    })
  })

  describe('authentication parameters', () => {
    it('should support authentication parameter', () => {
      const testCases = [
        'sqlserver://localhost:1433;database=testdb;authentication=DefaultAzureCredential',
        'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryIntegrated',
        'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryInteractive',
      ]
      testCases.forEach((connectionString) => {
        const config = parseConnectionString(connectionString)

        expect(config.user).toBe(undefined)
        expect(config.password).toBe(undefined)
        expect(config.authentication?.type).toBe('azure-active-directory-default')
      })
    })

    it('should support authentication password parameters', () => {
      const connectionString =
        'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryPassword;userName=user1;password=mypassword;clientId=my-client-id'
      const config = parseConnectionString(connectionString)

      expect(config.authentication?.type).toBe('azure-active-directory-password')
      if (config.authentication?.type === 'azure-active-directory-password') {
        expect(config.authentication?.options?.clientId).toBe('my-client-id')
        expect(config.authentication?.options?.userName).toBe('user1')
        expect(config.authentication?.options?.password).toBe('mypassword')
        expect(config.authentication?.options?.tenantId).toBe('')
      } else {
        throw new Error('expected config.authentication.type to be azure-active-directory-password')
      }
    })

    it('should support authentication managed identity parameters', () => {
      const testCases = [
        'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryManagedIdentity;clientId=test-client',
        'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryMSI;clientId=test-client',
      ]
      testCases.forEach((connectionString) => {
        const config = parseConnectionString(connectionString)


Review comment (security):
could use `it.each`
```suggestion
    it.each([
      'sqlserver://localhost:1433;database=testdb;authentication=DefaultAzureCredential',
      'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryIntegrated',
      'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryInteractive',
    ])('should support authentication parameter for %s', (connectionString) => {
      const config = parseConnectionString(connectionString)
      expect(config.user).toBe(undefined)
      expect(config.password).toBe(undefined)
      expect(config.authentication?.type).toBe('azure-active-directory-default')
    })
```

Code after:

    it('should handle connection string with malformed key-value pairs', () => {
      const connectionString = 'sqlserver://localhost;database=testdb;=value;key=;='
      const config = parseConnectionString(connectionString)

      expect(config.server).toBe('localhost')
      expect(config.database).toBe('testdb')
      // Should ignore malformed pairs
    })
  })

  describe('authentication parameters', () => {
    it.each([
      'sqlserver://localhost:1433;database=testdb;authentication=DefaultAzureCredential',
      'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryIntegrated',
      'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryInteractive',
    ])('should support authentication parameter for %s', (connectionString) => {
      const config = parseConnectionString(connectionString)
      expect(config.user).toBe(undefined)
      expect(config.password).toBe(undefined)
      expect(config.authentication?.type).toBe('azure-active-directory-default')
    })

    it('should support authentication password parameters', () => {
      const connectionString =
        'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryPassword;userName=user1;password=mypassword;clientId=my-client-id'
      const config = parseConnectionString(connectionString)

      expect(config.authentication?.type).toBe('azure-active-directory-password')
      if (config.authentication?.type === 'azure-active-directory-password') {
        expect(config.authentication?.options?.clientId).toBe('my-client-id')
        expect(config.authentication?.options?.userName).toBe('user1')
        expect(config.authentication?.options?.password).toBe('mypassword')
        expect(config.authentication?.options?.tenantId).toBe('')
      } else {
        throw new Error('expected config.authentication.type to be azure-active-directory-password')
      }
    })

    it.each([
      'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryManagedIdentity;clientId=test-client;msiEndpoint=msi-endpoint-1;msiSecret=msi-secret-1',
      'sqlserver://localhost:1433;database=testdb;authentication=ActiveDirectoryMSI;clientId=test-client;msiEndpoint=msi-endpoint-1;msiSecret=msi-secret-1',
    ])('should support authentication managed identity parameters for %s', (connectionString) => {
      const config = parseConnectionString(connectionString)

      expect(config.user).toBe(undefined)
      expect(config.password).toBe(undefined)
      expect(config.authentication?.type).toBe('azure-active-directory-msi-app-service')
      if (config.authentication?.type === 'azure-active-directory-msi-app-service') {
        expect(config.authentication?.options?.clientId).toBe('test-client')
        // @ts-expect-error tedious typings do not include msiEndpoint