Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZSS has broken PUT API request (UNIX API - writes contents to file or creates non-empty file) #474

Open
AdarshdeepCheema opened this issue May 17, 2022 · 2 comments
Assignees
Labels
bug Something isn't working zss

Comments

@AdarshdeepCheema
Copy link

AdarshdeepCheema commented May 17, 2022

Steps to reproduce:

  1. open the API Catalog and go to ZSS APIs
  2. try the below API
    Screen Shot 2022-05-17 at 4 29 16 PM
  3. Add the details like directory, file, body, sessionID, sourceEncoding. targetEncoding, last Chunk, forceOverwite
    Problem # 1: You will be wondering what should we add in sessionID as the field is mandatory.
    As per the API doc and API behaviour Please note that your first request will fail because you haven't been assigned a sessionID. If you don't have a sessionID in your request, then the server will assign you one and send it as a response. Please attach this sessionID to every subsequent request as a query parameter. This sessionID is linked to a particular file, so you must use it for the duration of the upload. If you lose it, then the file will be inaccessible via this API until your session timesout in five minutes.
    as shown in above screenshot.

WE SHOULD MAKE SESSION ID FIELD NOT MANDATORY. So that we can run the API for the first time to get the session ID.
4. Try the same URL in some third party tool like Insomnia and do not add the session ID in the URL. Also add the body content to write into the FIle. The request will give u a session ID back and it will create an empty file if the file does not exist.
For example: try to create the file APIFILE under /u/zowe/testing
https://server:port/zss/api/v1/unixfile/contents/%2Fu%2Fzowe%2Ftesting/APIFILE?sourceEncoding=UTF-8&targetEncoding=UTF-8&lastChunk=false&forceOverwrite=true
5. Now use this session ID in the API catalog and try the API as we tried in Step 3. It will work.
6. Go in editor and open the file.
Problem # 2: You will not see the content that you were trying to add into the file but you will find the below mentioned function with return code getting added to the file, each time we try to run the API.

int main() {
  return 0;
}

Screen Shot 2022-05-17 at 4 37 16 PM

@AdarshdeepCheema AdarshdeepCheema added zss bug Something isn't working labels May 17, 2022
@1000TurquoisePogs 1000TurquoisePogs transferred this issue from zowe/zlux May 17, 2022
@jordanfilteau1995
Copy link
Contributor

jordanfilteau1995 commented May 18, 2022

Background

You can upload the file in chunks or you can treat the entire file as a single chunk. There is a query parameter that you must attach, lastChunk, that controls this behavior.

If you are using this for file editing, then lastChunk=true is sufficient. If you are using this for file uploading, then lastChunk=false is useful, as it will append the body of each previous request to the file until lastChunk=true is received.

You are being expected to provide a base-64 encoded body with every PUT request to /contents.

Problems

(1) The field should be made not mandatory so that you can use tools like above. It is exactly as you stated; the first request will fail.

(2) This is the intended behavior since you are using lastChunk=false. It will keep appending the body of the request to the file until it times out or you use lastChunk=true. I think the code snippet, int main() { return 0; }, is coming from whatever tool you are using to send the request. It is probably aW50IG1haW4oKSB7CiAgcmV0dXJuIDA7Cn0= being sent each time you send the request.

@AdarshdeepCheema
Copy link
Author

AdarshdeepCheema commented May 19, 2022

@jordanfilteau1995 regarding (2): Yes I have intentionally set the lastChunk=false to add the content at the end of the file each time I send the API request.
I have only used the Insomnia tool to run the API for the very first time and get the session ID. Once I had the session ID, I used the API from API catalog, to add the content to the file. But it was adding int main() { return 0; } instead of aW50IG1haW4oKSB7CiAgcmV0dXJuIDA7Cn0=
Then I opened the Editor and tried to check the response when I open the File, The response had "aW50IG1haW4oKSB7CiAgcmV0dXJuIDA7Cn0=" in it is shown as int main() { return 0; } in editor.

I tried to decode aW50IG1haW4oKSB7CiAgcmV0dXJuIDA7Cn0= and it gets decodes to int main() { return 0; }
SO IT SEEMS LIKE WORKING AS EXPECTED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working zss
Projects
None yet
Development

No branches or pull requests

3 participants