I’ve been debugging for days to get my Ionic app working with the Laravel API backend.
The issue: logging in worked fine, but every subsequent API request failed with a 401.
The reason (I guess): the Ionic/capacitor app works with a referrer of capacitor://localhost
. I think this messes up the cookie that is set to maintain the session.
So I had to switch over to something without cookies. Having already spend days on the issues, I went to work with JWT as I’ve done so before.
I followed this tutorial to get me a head-start: https://www.positronx.io/laravel-jwt-authentication-tutorial-user-login-signup-api/
When you want your tests to be able to run whenever you want, you should use values which are random.
In Postman, click on the name of Collection and then open the ‘Pre-request Script’ tab.
There, add the following:
// get a random number between a minimum and a maximum
// gives you current datetime with milliseconds like 2022810_171012_174
postman.setGlobalVariable("getCurrentDate", () => {
const date=new Date();
return String(date.getFullYear())
+ String(date.getMonth()+1)
+ String(date.getDate())
+ '_'
+ String(date.getHours() < 10 ? "0"+date.getHours() : date.getHours())
+ String(date.getMinutes() < 10 ? "0"+date.getMinutes() : date.getMinutes())
+ String(date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds())
+ '_'
+ String(date.getMilliseconds())
})
You can now use this function in your tests. This enables you to make your strings (like emailaddresses) random by adding the current datetime to it.
To use it, open your test, click on the ‘Pre-request Script’ tab and add the following.
var currentDate = eval(pm.globals.get("getCurrentDate"))();
var randomEmail = `postman-${currentDate}@pauledenburg.com`;
pm.environment.set("randomEmail", randomEmail);
You can now use the generated value in the body of your POST-request by referencing it as {{randomEmail}}
The full warning is:
Warning
(2728:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
The easy fix:
rename color-adjust
to print-color-adjust
This didn’t work for me as the issue is in the node_modules
directory.
Other fix: add the following to your package.json
:
"resolutions": {
"autoprefixer": "10.4.5"
},
Then run the following again: yarn install
Sometimes you want to use child/parent like tests.
This enables you to treat the ‘child test’ more like a template which you can re-use. But you might want to influence the variable used in this templated test.
To test whether a variable was set and set it when it was not, you’d do the following.
Testing whether a variable was set is done with this javascript string:
"${randomResellerEmail}" == "$" + "{randomResellerEmail}"
In Selenium IDE this looks like the following.
I use variables all the time. And to be able to re-use a test over and over again, I need random email addresses whenever I fill in forms.
For this I define a variable with the current date and time and then a variable which will hold the email address which uses the current date and time.
My random email address will look like: selenium-20220318_122803@pauledenburg.com
Just store the following as 1 string into the ‘Target’ part of your command.
const date=new Date(); return String(date.getFullYear()) + String(date.getMonth()+1) + String(date.getDate()) + '_' + String(date.getHours() < 10 ? "0"+date.getHours() : date.getHours()) + String(date.getMinutes() < 10 ? "0"+date.getMinutes() : date.getMinutes()) + String(date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds())
It will look like this in Selenium IDE:
Now you can use this to create your email address which is unique every time you run your test:
And use it when you want to fill a form.
In your .json
definition file:
{
"swagger": "2.0".
...
"securityDefinitions": {
"bearerAuth": {
"type": "apiKey",
"in": "header",
"name": "Authorization",
}
},
...
"paths": {
"get": {
"/path": {
"security": [
{"bearerAuth": []}
],
...
}
}
}
official documentation is here: https://swagger.io/docs/specification/authentication/bearer-authentication/
git diff --word-diff=color dump1.sql dump2.sql | less -R
Answer taken from here: https://stackoverflow.com/a/57164008
The quick way:
git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d
git remote prune origin
Use the following to have the branches displayed before you’re asked to delete them.
branches=$(git branch --merged master | grep -v '^[ *]*master$'); \
printf '\n\nBranches to be removed:\n---\n'; \
echo ${branches} | xargs -n1; \
printf '---\n\nRemove the branches above? [Ny] ' \
&& read shouldDelete \
&& [[ "${shouldDelete}" =~ [yY] ]] \
&& echo $branches | xargs git branch -d \
|| echo 'aborted'
In your migration, add this as an option to the table:
$this->table(
'specific_costs_users',
['collation'=>'utf8mb4_unicode_ci']
)
->addColumn(...)
I found the answer here on StackOverflow
I noticed today that my server was very slow. Looking at the running processes, I noted that process wanwakuang
and 000000
were going crazy.
Searching wanwakuang
on Google did not yield much results, but this article on HackerNews was very helpful: https://translate.google.com/translate?sl=auto&tl=en&u=http://hackernews.cc/archives/34789
Appearently wanwakuang is a mining process.
However, I could not find the binary on my system. My server is only running Docker containers, so probably one of the containers was at fault.
To find the docker container with the exploit, I executed the command:
$ find /var/lib/docker -type f -name wanwakuang /var/lib/docker/overlay2/1752e86653539d82b50cf24c3d3f69b203fe059ca1650447016ca69033d468bf/diff/root/.configrc/a/wanwakuang /var/lib/docker/overlay2/1752e86653539d82b50cf24c3d3f69b203fe059ca1650447016ca69033d468bf/diff/tmp/.W10-unix/.rsync/a/wanwakuang /var/lib/docker/overlay2/1752e86653539d82b50cf24c3d3f69b203fe059ca1650447016ca69033d468bf/merged/root/.configrc/a/wanwakuang /var/lib/docker/overlay2/1752e86653539d82b50cf24c3d3f69b203fe059ca1650447016ca69033d468bf/merged/tmp/.W10-unix/.rsync/a/wanwakuang
To find out which Docker container was attached to this overlay, I issued this command I found on stackoverflow:
$ docker inspect $(docker ps -qa) \ | jq -r 'map([.Name, .GraphDriver.Data.MergedDir]) \ | .[] | "(.[0])\t(.[1])"' \ | grep '1752e86653539d82b50cf24c3d3f69b203fe059ca1650447016ca69033d468bf'
Knowing the name I could terminate the container. It was being used for SSH and could be removed.