Now that we’ve automated certificate setup on our development machine, it’s time to extend this setup to our mobile test devices.
This ensures seamless testing across both your local machine and devices like an iOS simulator or physical mobile devices.
To test on the iOS simulator, we need to make the root certificate authority accessible. A convenient way to do this is by linking the root certificate to the public folder so it can be easily downloaded:
# bin/setup
system %q{ln -sf "$(mkcert -CAROOT)/rootCA.pem" public/rootCA.pem}
This setup makes the root certificate available in our project’s public folder.
For testing on physical mobile devices, we also need to add our machine’s IP addresses to the certificate. Here’s how to do that:
require "socket"
ips = Socket.ip_address_list.filter { _1.ipv4_private? }.collect(&:ip_address)
system %Q{mkcert --cert-file localhost.pem --key-file localhost-key.pem localhost #{ips.join(" ")}}
This creates a certificate valid for localhost
and all private IP addresses of your machine, ensuring the same certificate works across devices.
Once the certificate is ready:
After completing these steps, your local and mobile devices will be set up for secure testing.