pavansai1997 opened a new pull request, #76355:
URL: https://github.com/apache/airflow/pull/76355

   `FTPHook.test_connection` has read `conn.pwd` without calling it since it 
was added in #21997, so testing an FTP connection never sends a command to the 
server. `get_conn` skips `connect()` when the connection has no host and skips 
`login()` when it has no login, so both of those connections were reported as 
"Connection successfully tested" even though they cannot work.
   
   The test now calls `pwd()`. `PWD` needs a logged-in session on most servers, 
which makes it a meaningful check: `NOOP` is accepted before login (a test 
server answers `200` to `NOOP` and `530 Log in with USER and PASS first.` to 
`PWD`), so it would keep the false positive for a missing login. This matches 
`SFTPHook.test_connection`, which calls `normalize(".")`.
   
   A connection without a host would now fail with ftplib's `'NoneType' object 
has no attribute 'sendall'`, because `pwd()` runs on a socket that was never 
opened. The host check before `get_conn()` replaces that with "Connection has 
no host to connect to"; it changes the message, not the result.
   
   `FTPSHook` inherits the method. Its `get_conn` already contacts the server 
through the `FTP_TLS` constructor and `prot_p()`, so FTPS results do not change 
apart from the no-host message.
   
   Results against a local pyftpdlib server that requires login (FTPS with 
certificate verification enabled):
   
   | Connection | FTP before | FTP after | FTPS before | FTPS after |
   |---|---|---|---|---|
   | Valid credentials | success | success | success | success |
   | Wrong password | `530 Authentication failed.` | same | same | same |
   | No login | **success** | `530 Log in with USER and PASS first.` | `503 
PBSZ not allowed on insecure control connection.` | same |
   | No host | **success** | `Connection has no host to connect to` | 
`'NoneType' object has no attribute 'sendall'` | `Connection has no host to 
connect to` |
   
   The FTP hook tests pass, and the three new tests fail without the change.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Code Puppy
   
   Generated-by: Code Puppy following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to